Skip to content

Instantly share code, notes, and snippets.

@mungomash
Created January 7, 2012 20:08
Show Gist options
  • Save mungomash/1575865 to your computer and use it in GitHub Desktop.
Save mungomash/1575865 to your computer and use it in GitHub Desktop.
Adding additional methods in Ruby
require 'date'
class Weeks
def initialize(number)
@number = number
end
def ago
return Date.today - (@number * 7)
end
end
class Fixnum
def weeks
return Weeks.new(self)
end
end
puts 2.weeks.ago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment