If I have a class and a module:
class Foo
end
module WhackyFoo
def whacky
puts 'shits whacky!'
end
end
Why can I do this:
include WhackyFoo
Foo.new.whacky
# => shits whacky!
Can someone explain or point me to the Ruby docs where this usage is explained?
Because when you include module on the top level, it gets included into a special object
main. Any method defined onmain(including those included from module) become private instance methods ofObject(and, therefore, all objects). That’s why it works.If you include a module into a “normal” class (not top level
main), it behaves as you would expect