Skip to content

Instantly share code, notes, and snippets.

@achambers
Created August 26, 2011 16:24
Show Gist options
  • Save achambers/1173794 to your computer and use it in GitHub Desktop.
Save achambers/1173794 to your computer and use it in GitHub Desktop.
Include vs Extend
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