Created
May 7, 2013 08:52
-
-
Save deepak/5531231 to your computer and use it in GitHub Desktop.
method defined on the eigenclass shadows the instance method
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
| # method defined on the eigenclass shadows the instance method | |
| require 'pp' | |
| class A | |
| def foo; "A"; end | |
| end | |
| a1 = A.new | |
| a2 = A.new | |
| mk = class << a1 | |
| self | |
| end | |
| pp mk.object_id == a1.object_id #=> false | |
| class << a1 | |
| def foo; "meta"; end | |
| end | |
| pp a1.foo #=> "meta" | |
| pp a2.foo #=> "A" | |
| __END__ | |
| ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin10.8.0] | |
| false | |
| "meta" | |
| "A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment