Last active
August 29, 2015 14:09
-
-
Save brenes/c556ed0d0070e27444b5 to your computer and use it in GitHub Desktop.
extending objects through modules
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 A | |
| def to_s | |
| "a" | |
| end | |
| end | |
| module B | |
| def to_s | |
| super + "b" | |
| end | |
| end | |
| a = A.new | |
| puts a.to_s # => a | |
| b = A.new | |
| puts b.to_s # => a | |
| b.extend B | |
| puts a.to_s # => a | |
| puts b.to_s # => ab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment