Created
September 11, 2015 01:54
-
-
Save xuncheng/0ba83a5a160963a53809 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
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