RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Ruby Interview Questions : Include vs Extend

What is the difference between include and extend? How to implement extend with include? Watch the video here: Include and Extend

Comments

This does not really explain the difference between include and extend. My understanding is that include differs from extend in that it can it instance methods to a class. A common ruby idiom is to also add class methods via the included hook plus extend.

I’m not sure why you would want to use include to add class methods (without going through the included hook) versus extend as shown above in the video.

Here’s a much better explanation in my opinion: http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/

I have made the correction. The video does not address the question: What is the difference between include and extend?

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in