I mean, I want to create a class method in my module that will be used by the class who includes the module. They are in separated files.
By far I have something like th
You can extend
the module in your class, your code should be like this:
module Base
def all
puts "All Users"
end
end
class User
extend Base
end
When you do something like this:
module MyModule
def self.module_method
puts "module!"
end
end
You're actually adding the method in the module itself, you could call the previous method like this:
MyModule.module_method
There is a way to just include the module
and get the behaviour that you want, but I don't think this could be considered the "way to go". Look at the example:
module Base
def self.included(klass)
def klass.all
puts "all users"
end
end
end
class User
include Base
end
But like I said, if you can go with the extend
class method, it is a better suit.