Created
March 21, 2010 13:07
-
-
Save NV/339293 to your computer and use it in GitHub Desktop.
Ruby's anonymous classes
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
| dog = 'Bob' | |
| class << dog | |
| def what | |
| self | |
| end | |
| end | |
| dog.what #'Bob' | |
| ''.what #NoMethodError | |
| # Programming Ruby, The Pragmatic Programers (2nd, 2005) | |
| # page 368 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment