You can either use include or extend to mix in a module’s functionality into a class. The difference is this:
include makes the module’s methods available to the instance of a class, whileextend makes these methods available to the class itself.Check out this example:
module Greetings
def say_hello
puts "Hello!"
end
end
class Human
include Greetings
end
Human.new.say_hello # => "Hello!"
Human.say_hello # NoMethodError
class Robot
extend Greetings
end
Robot.new.say_hello # NoMethodError
Robot.say_hello # => "Hello!"
If you want more information on include vs. extend, I recommend the following resources:
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.