Skip to content

Instantly share code, notes, and snippets.

@xuncheng
Created September 11, 2015 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuncheng/0ba83a5a160963a53809 to your computer and use it in GitHub Desktop.
Save xuncheng/0ba83a5a160963a53809 to your computer and use it in GitHub Desktop.
module Foo
def bar
puts 'foobar'
end
end
class IncludeModule
include Foo
end
class ExtendModule
extend Foo
end
class Plain; end
IncludeModule.bar # => undefined method `bar' for IncludeModule:Class (NoMethodError)
IncludeModule.new.bar # => 'foobar'
ExtendModule.bar # => 'foobar'
ExtendModule.new.bar # => undefined method `bar' for #<ExtendModule:0x007f848197aee8> (NoMethodError)
plain = Plain.new
plain.bar # => undefined method `bar' for #<Plain:0x007fb252086f90> (NoMethodError)
plain.extend(Foo)
plain.bar # => 'foobar'
new_plain = Plain.new
new_plain.bar # => undefined method `bar' for #<Plain:0x007fb252086f90> (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment