Created
January 2, 2014 10:50
-
-
Save huyderman/8217568 to your computer and use it in GitHub Desktop.
12 Days of Christmas
via rounin (http://rounin.livejournal.com/23870.html) with improvments by me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
days = %w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth) | |
things = ['a partridge in a pear tree', 'two turtledoves', 'three French hens', 'four calling birds', 'five golden rings', 'six geese a-laying', 'seven swans a-swimming', 'eight maids a-milking', 'nine ladies dancing', 'ten lords a-leaping', 'eleven pipers piping', 'twelve drummers drumming'] | |
days.each_with_index do |day, i| | |
puts "On the #{day} day of Christmas, my true love sent to me:" | |
day_things = things[0..i].reverse.each_with_index.map do |thing, j| | |
case j | |
when 0 thing.capitalize | |
when i "and #{thing}" | |
else thing | |
end | |
end | |
puts day_things.join(",\n") << ".\n\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment