Skip to content

Instantly share code, notes, and snippets.

@mdaisuke
Created February 10, 2011 07:40
Show Gist options
  • Save mdaisuke/820103 to your computer and use it in GitHub Desktop.
Save mdaisuke/820103 to your computer and use it in GitHub Desktop.
object expansion
module YMD
def year
self.split("-")[0]
end
def month
self.split("-")[1]
end
def day
self.split("-")[2]
end
end
date = "2010-12-17"
class << date
include YMD
end
# or "date.extend YMD" can be replaced with above
p date.year #=> "2010"
p date.month #=> "12"
p date.day #=> "17"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment