Is it possible to declare static methods in a module in ruby?
module Software
def self.exit
puts "exited"
end
end
class Windows
include Software
def self.start
puts "started"
self.exit
end
end
Windows.start
The example above will not print out “exited”.
Is it only possible to have instance methods in a module?
Define your module like this (i.e. make
exitan instance method in the module):and then use
extendrather thanincludeIn use:
Explanation
…so when used within the context of a class definition (with the class itself as the receiver) the methods become class methods.