Created
February 26, 2009 13:06
-
-
Save sheldonh/70827 to your computer and use it in GitHub Desktop.
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 | |
class Geoff | |
def initialize(numeric = nil) | |
numeric ||= 1 | |
@number = numeric.to_i | |
end | |
def to_s | |
["Geoff", title].join(" ") | |
end | |
private | |
def title | |
"the #{@number.ordinate}" | |
end | |
end | |
class Integer | |
def to_geoff | |
Geoff.new(self) | |
end | |
def ordinate | |
case self.to_s[-1,1] | |
when "1" | |
"#{self}st" | |
when "2" | |
"#{self}nd" | |
when "3" | |
"#{self}rd" | |
else | |
"#{self}th" | |
end | |
end | |
end | |
1.upto(10) do |generation| | |
puts generation.to_geoff | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment