Skip to content

Instantly share code, notes, and snippets.

@eiwi1101
Created December 22, 2016 18:19
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 eiwi1101/c90526fb499711eb34d455f32642ba79 to your computer and use it in GitHub Desktop.
Save eiwi1101/c90526fb499711eb34d455f32642ba79 to your computer and use it in GitHub Desktop.
# As if Ruby didn't make dates any easier, this!
# (#method_missing is disgusting and I love it.)
#
# 25.december 2015 #=> Fri, 25 Dec 2015
#
class Fixnum
def method_missing(month, year=nil)
Date::MONTHNAMES.each_with_index do |m, i|
return Date.new year, i, self if m && month.to_s.casecmp(m)==0
end
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment