Skip to content

Instantly share code, notes, and snippets.

@dansteele

dansteele/demo.rb

Last active Jan 12, 2016
Embed
What would you like to do?
Dynamic stuff for Austin
class Person
def initialize(name)
@name = name
end
end
austin = Person.new("Austin")
austin.define_singleton_method "speak" do
"Hi, my name is #{@name}"
end
austin.speak
#=> Hi, my name is Austin
Person.class_eval do
def speak
"Hi my name is #{@name}"
end
end
dan = Person.new("Dan")
dan.speak
#=> "Hi, my name is Dan"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment