LoginSignup
28
26

More than 5 years have passed since last update.

♥Enumerator を使ったシンプルな FizzBuzz♥

Last updated at Posted at 2012-12-01

Enumerator を使ったシンプルな FizzBuzz です。

fizzer = [nil, nil, 'Fizz'].cycle
buzzer = [nil, nil, nil, nil, 'Buzz'].cycle
1.upto(100) { |i|
  fizz, buzz = fizzer.next, buzzer.next
  puts fizz || buzz ? "#{fizz}#{buzz}" : i
}

Array#cycle がクールですね♥

28
26
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
26