Created
November 7, 2012 06:34
-
-
Save jeffreyiacono/4029861 to your computer and use it in GitHub Desktop.
Ruby eigenclass example
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
| # alternatively | |
| class Dog | |
| def bark | |
| puts "bark bark" | |
| end | |
| end | |
| fido = Dog.new | |
| rex = Dog.new | |
| fido.bark | |
| # => "bark bark" | |
| rex.bark | |
| # => "bark bark" | |
| # tap into rex's eigenclass | |
| class << rex | |
| def bark | |
| puts "barking is so 2011" | |
| end | |
| end | |
| fido.bark | |
| # => "bark bark" | |
| rex.bark | |
| # => "barking is so 2011" |
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
| class Dog | |
| def bark | |
| puts "bark bark" | |
| end | |
| end | |
| fido = Dog.new | |
| rex = Dog.new | |
| fido.bark | |
| # => "bark bark" | |
| rex.bark | |
| # => "bark bark" | |
| # tap into rex's eigenclass | |
| def rex.bark | |
| puts "barking is so 2011" | |
| end | |
| fido.bark | |
| # => "bark bark" | |
| rex.bark | |
| # => "barking is so 2011" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment