How to access a Ruby Module method

If you include the module the method becomes an instance method but if you extend the module then it becomes a class method.

module Const
  def format
    puts 'Done!'
  end
end

class Car
  include Const
end

Car.new.format # Done!
Car.format # NoMethodError: undefined method format for Car:Class

class Bus
  extend Const
end

Bus.format # Done!
Bus.new.format # NoMethodError: undefined method format

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)