Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created November 12, 2011 16:27
Show Gist options
  • Save brianstorti/1360770 to your computer and use it in GitHub Desktop.
Save brianstorti/1360770 to your computer and use it in GitHub Desktop.
Open classes
var = "foo"
class MyClass
def my_method
puts "my_method()"
end
end
class MyClass
def another_method
puts "another_method()"
end
end
my_instance = MyClass.new
my_instance.my_method # => "my_method()"
my_instance.another_method # => "another_method()"
class MyClass
def my_method
puts "my_method() modified"
end
end
my_instance.my_method # => "my_method() modified"
class String
def to_s
puts "just modified string's to_s()"
end
end
"string".to_s # => "just modified string's to_s()"
class Fixnum
def +(value)
self - value
end
end
5 + 3 # => 2
cents = 999
price = Money.new(cents)
price = 999.to_money
class Numeric
def to_money
Money.new(self * 100)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment