Created
December 6, 2010 08:07
-
-
Save deepak/730004 to your computer and use it in GitHub Desktop.
a reserved function - to guard against the definition of a common function
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
| # objective is to guard against a definition of a function | |
| # eg. a common error is to define 'def included' rather than 'def self.included' | |
| # also can i have a 'def self.included' whenever 'def included' - with the same content | |
| class Object | |
| def self.method_added(p1) | |
| puts "== method_added: #{p1.inspect} | #{p1.class}" | |
| raise "common_bug: maybe you want to use self.included rather than included" if p1 == :included | |
| end | |
| end | |
| class Module | |
| def self.method_added(p1) | |
| puts "== method_added: #{p1.inspect} | #{p1.class}" | |
| raise "common_bug: maybe you want to use self.included rather than included" if p1 == :included | |
| end | |
| end | |
| class Bar #error thrown - Bar not defined | |
| def included | |
| # hook called | |
| end | |
| end | |
| module Foo #error not thrown - Foo is defined | |
| def included | |
| # hook called | |
| end | |
| end | |
| class Baz #error not thrown - Baz is defined | |
| include Foo | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment