General question about Ruby Eigenclass/Singleton
- by Dex
module MyModule
def my_method; 'hello'; end
end
class MyClass
class << self
include MyModule
end
end
MyClass.my_method # => "hello
I'm unsure why "include MyModule" needs to be in the eigenclass in order to be called using just MyClass.
Why can't I go:
X = MyClass.new
X.my_method
How is this type of pattern useful if I can't call it from an instance?