Last active
January 12, 2016 17:10
-
-
Save dansteele/650111ec1baa7f0d906e to your computer and use it in GitHub Desktop.
Dynamic stuff for Austin
This file contains hidden or 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
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