Skip to content

Instantly share code, notes, and snippets.

@arnab
Last active December 11, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnab/4585462 to your computer and use it in GitHub Desktop.
Save arnab/4585462 to your computer and use it in GitHub Desktop.
the_clone = p.clone
the_dup = p.dup
irb(main):018:0> the_clone.name
=> "The Man"
irb(main):019:0> the_dup.name
=> "The Man"
irb(main):020:0> the_clone.say_hi
=> "'sup"
irb(main):021:0> the_dup.say_hi
NoMethodError: undefined method `say_hi' for
(Person :0xb7e83340 @name="The Man")
from (irb):21
from :0
irb(main):022:0>
class Person
attr_accessor :name
end
p = Person.new
p.name = "The Man"
# now add a singleton method on p:
def p.say_hi
"'sup"
end
irb(main):014:0> puts p.inspect
#<person :0xb7e83340 @name="The Man">
=> nil
irb(main):015:0> puts p.say_hi
'sup
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment