Skip to content

Instantly share code, notes, and snippets.

@maxim
Created July 8, 2009 02:57
Show Gist options
  • Select an option

  • Save maxim/142527 to your computer and use it in GitHub Desktop.

Select an option

Save maxim/142527 to your computer and use it in GitHub Desktop.
# 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