Skip to content

Instantly share code, notes, and snippets.

@dskecse
Created June 6, 2016 15:02
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 dskecse/9bce0076c5e99b8efa45f59e61067c17 to your computer and use it in GitHub Desktop.
Save dskecse/9bce0076c5e99b8efa45f59e61067c17 to your computer and use it in GitHub Desktop.
see how #clone copies singleton methods
irb(main):001:0> str = 'This is my STRING!'
=> "This is my STRING!"
irb(main):002:0> def str.-@
irb(main):003:1* downcase
irb(main):004:1> end
=> :-@
irb(main):005:0> p str
"This is my STRING!"
=> "This is my STRING!"
irb(main):006:0> p -str
"this is my string!"
=> "this is my string!"
irb(main):007:0> s = str
=> "This is my STRING!"
irb(main):008:0> s.equal? str
=> true
irb(main):009:0> p -str
"this is my string!"
=> "this is my string!"
irb(main):010:0> ss = str.clone
=> "This is my STRING!"
irb(main):011:0> p -ss
"this is my string!"
=> "this is my string!"
irb(main):012:0> ss.equal? str
=> false
irb(main):013:0> sss = str.dup
=> "This is my STRING!"
irb(main):014:0> sss.equal? str
=> false
irb(main):015:0> p -sss
"This is my STRING!"
=> "This is my STRING!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment