Created
June 6, 2016 15:02
-
-
Save dskecse/9bce0076c5e99b8efa45f59e61067c17 to your computer and use it in GitHub Desktop.
see how #clone copies singleton methods
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
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