Created
July 8, 2009 02:57
-
-
Save maxim/142527 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
| # On include we're grepping method baz from instance methods | |
| module Foo | |
| def self.included(base) | |
| puts base.instance_methods.grep(/baz/).inspect | |
| end | |
| end | |
| class Bar | |
| include Foo | |
| def baz; end | |
| end | |
| # prints [] -- no method baz found! | |
| class Bar | |
| include Foo | |
| end | |
| # prints ["baz"] -- now that we re-opened same class method already there | |
| class Qux | |
| def baz; end | |
| include Foo | |
| end | |
| # prints ["baz"] -- since baz is declared before inclusion of Foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment