Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'time'
- class Time
- private
- def hour_to_words(hr)
- puts self
- case hr
- when 12 then "noon"
- when 0,24 then "midnight"
- else ['zero','one','two','three','four','five','six','seven',
- 'eight','nine','ten','eleven'][hr % 12]
- end
- end
- public
- def humanize
- "About " +
- case self.min # what minute is it?
- when 0..7 then "#{hour_to_words(hour)}"
- when 8..22 then "a quarter after #{hour_to_words(hour)}"
- when 23..37 then "half past #{hour_to_words(hour)}"
- when 38..52 then "a quarter til #{hour_to_words(hour+1)}"
- when 53..59 then "#{hour_to_words(hour+1)}"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement