The difference between include and extend in Ruby on Rails.

Instance methods, include and extend, are usually seen when we use modules. Because I didn’t know the difference between them, I’m going to write it down.

module Bar
def b
'ok Bar'
end
end

obj = Object.new
obj.extend Bar
p obj.b #=> "ok Bar"

class Klass
extend Bar
end

p Klass.b #=> "ok Bar"

Class can use methods which are extended as an instance method.

module Foo
def a
'ok Foo'
end
end
obj = Object.new
obj.extend Foo
p obj.a #=> "ok Foo"

class Klass
include Foo
end

p Klass.new.a #=> "ok Foo"

Class can use methods which are extended as an instance method.