Skip to content

Instantly share code, notes, and snippets.

@drtoast
Created June 29, 2010 17:28
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 drtoast/457521 to your computer and use it in GitHub Desktop.
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
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