Created
June 29, 2010 17:28
-
-
Save drtoast/457521 to your computer and use it in GitHub Desktop.
A more elegant solution for: http://thedailywtf.com/Articles/Got_Time_0x3f_.aspx
This file contains hidden or 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
# A more elegant solution for: http://thedailywtf.com/Articles/Got_Time_0x3f_.aspx | |
class DH | |
def hours_to_days_and_hours(hours) | |
self.send "days_and_hours_in_#{hours}_hours" | |
end | |
def method_missing(method) | |
method.to_s.match(/(\d+)/) | |
hours = $1 | |
puts "adding new instance method: #{method}" | |
self.class.class_eval <<-end_eval | |
def #{method} | |
d = #{hours} / 24 | |
h = #{hours} % 24 | |
return [d,h] | |
end | |
end_eval | |
self.send method | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment