Created
February 10, 2011 07:40
-
-
Save mdaisuke/820103 to your computer and use it in GitHub Desktop.
object expansion
This file contains 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
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