Hi all,
Visibility issues within a module are not entirely clear to me. I was
writing a little Ruby module in the process of learning the language,
but found myself facing with a behaviour I considered quite strange.
The guts of my problem is summarized by the following case study:
module A1
def f; puts 'A1::f'; end
module_function :f
end
module A2
def f; g; end;
def g; puts 'g'; end
module_function :f
end
module A3
def f; g; end;
private
def A3.g; puts 'A3.g'; end
module_function :f
end
Now, if I call A1::f, I get 'A1::f' printed on output, and that's OK.
Problems arise whenever I call A2::f and A3.g! The call to A2::f fails
because a NameError is raised, telling me about an undefined local
variable or method g for A2 module, which, ahem, it seems to me it's
plain false, since a g function is definetely defined in module A2. The
call to A3.g, then, prints 'A3.g' on output, but that should not happen
because I defined that function to be private in the module.
So, what's really happening? I'm puzzled!
Thanks in advance,
Giulio Piancastelli.