Created
September 22, 2013 10:59
-
-
Save ngpestelos/6658895 to your computer and use it in GitHub Desktop.
class eval
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
| # see Metaprogramming Ruby, p. 93 | |
| def add_method_to(a_class) | |
| a_class.class_eval do | |
| def m; 'Hello!'; end | |
| end | |
| end | |
| add_method_to String | |
| puts "foo".m # Hello! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment