Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.upto 15 do |i|
- (out ||= '') << 'Fizz' if (i % 3).zero?
- (out ||= '') << 'Buzz' if (i % 5).zero?
- puts out || i
- # This will print FizzBuzz as expected
- end
- 1.upto 15 do |i|
- out ||= '' << 'Fizz' if (i % 3).zero?
- out ||= '' << 'Buzz' if (i % 5).zero?
- puts out || i
- # Omitting the parenthesis around the conditional assignment will fail printing FizzBuzz at 15
- end
Advertisement
Add Comment
Please, Sign In to add comment