Skip to content

Instantly share code, notes, and snippets.

@bswinnerton
Created April 1, 2014 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bswinnerton/9925082 to your computer and use it in GitHub Desktop.
Save bswinnerton/9925082 to your computer and use it in GitHub Desktop.
99.downto(1) do |i|
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} of beer on the wall"
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} bottles of beer!"
puts "You take one down and pass it around,"
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} bottles of beer on the wall!"
puts 'No more bottles of beer on the wall :-(' if i == 1
puts
end
@bswinnerton
Copy link
Author

Where i.between?(2,99) ? "bottles" : "bottle" evaluates to:

if i.between?(2,99)
  "bottles"
else
  "bottle"
end

This is known as a "ternary".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment