Skip to content

Instantly share code, notes, and snippets.

@deepak
Created December 6, 2010 08:07
Show Gist options
  • Select an option

  • Save deepak/730004 to your computer and use it in GitHub Desktop.

Select an option

Save deepak/730004 to your computer and use it in GitHub Desktop.
a reserved function - to guard against the definition of a common function
# 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