Created
January 12, 2011 14:02
-
-
Save alindeman/776188 to your computer and use it in GitHub Desktop.
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 Foo | |
| def self.blah | |
| "foo" | |
| end | |
| end | |
| puts Foo.blah # "foo" | |
| Foo.define_singleton_method :blah, do | |
| "hijink" | |
| end | |
| puts Foo.blah # "hijink" |
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 Foo | |
| def self.blah | |
| "foo" | |
| end | |
| end | |
| puts Foo.blah # "foo" | |
| module FooExtend | |
| def blah | |
| "hijink" | |
| end | |
| end | |
| Foo.singleton_class.send :extend, FooExtend | |
| puts Foo.blah # "foo" | |
| puts Foo.singleton_class.blah # "hijink" |
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 Foo | |
| def self.blah | |
| "foo" | |
| end | |
| end | |
| puts Foo.blah # "foo" | |
| singleton_class = class << Foo; self; end; | |
| def singleton_class.blah | |
| "hijink" | |
| end | |
| puts Foo.blah # "foo" | |
| puts singleton_class.blah # "hijink" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment