I understand the way these things are working but I don’t really
understand what’s going on and why.
module Foo
def bar
1
end
def Foo.zim
2
end
end
Foo.zim # works, OK, fair enough
2
Foo::zim # works, but why have two syntaxes that do the same?
2
Foo.bar # NoMethodError. Shouldn’t this work though? What if I had a procedural API that I wanted to namespace: -
module SomeNamespace
require ‘procedural_api’
end
SomeNamespace.function_from_procedural_api # this ain’t gonna work!
SomeNamespace::function_from_procedural_api # nor is this
class SomeClass
include Foo
end
SomeClass.new.bar # OK, it’s been mixed in
1
SomeClass.zim # NoMethodError, huh? Why doesn’t this work?
SomeClass.new.zim # NoMethodError. So where has the zim definition actually gone? Doesn’t it get included at all?
I’m very confused by all this. Please help unravel the mess in my brain.
Foo::zim # works, but why have two syntaxes that do the same?
2
objec.method works for any object. Everything is an object, so Foo is
an object too.
Class::method, Module::method works with class/module methods only.