Ruby 1.9.1 ããªãªã¼ã¹ããããã¨ã ãï¼æ°æ©è½ï¼Fiber 㨠Array#cycleï¼ã使ã£ã¦FizzBuzz ãæ¸ãã¦ã¿ãããd:id:takatoh:20070509:fizzbuzz ã®Rubyçã cf. Ruby 1.9.1 ã®æ©ãæ¹ - ãã³ã¾ 0025å· # -*- encoding: utf-8 -*- fizzbuzz = Fiber.new do fizz = ["", "", "Fizz"].cycle buzz = ["", "", "", "", "Buzz"].cycle n = 1 while s = fizz.next + buzz.next Fiber.yield(s == "" ? n.to_s : s) n += 1 end end 100.times{ puts fizzbuzz.resume } å®è¡çµæã¯çç¥ã 追è¨ï¼ Fiber ã£ã¦
{{#tags}}- {{label}}
{{/tags}}