Created
August 26, 2011 16:24
-
-
Save achambers/1173794 to your computer and use it in GitHub Desktop.
Include vs Extend
This file contains 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 Tweet | |
def save | |
puts 'Tweet saved' | |
end | |
end | |
class Foo | |
include Tweet # Add methods from Tweet as Instances Methods | |
end | |
class Bar | |
extend Tweet # Add methods from Tweet as Class Methods | |
end | |
Foo.save # => undefined method `save' for Foo:Class (NoMethodError) | |
Foo.new.save # => Tweet saved | |
Bar.save # => Tweet saved | |
Bar.new.save # => undefined method `save' for #<Bar:0x007f813104e0e8> (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment