I am trying to familiarize myself with modules and this code shows a name clash in main that I can not find any information on how to resolve using a namepace (only) with a module class instance variable. Perhaps not possible?
**Modified code slightly so "c = "MAIN"" is before "include" so no doubt that two c variables exist. Added class so I can specify 'cv::a' which I believe is an example of an explicit receiver as you mentioned. I deliberately created the name collision just to see if I could resolve it (main::c was defined before include in my original code from which this was snipped)
I guess my theoretical question becomes can I in some manner specify an explicit receiver (like M2.C) for the instance variable 'c' defined in a method, the similar to that of 'a' (cv::a) defined in a class.
I had decided probably not possible as I was unable to code a namespace to prefix 'c' but thought to ask thinking I had missed something. If this is possible using my code, could you show me how to do so.*
module M2
def method_vars() @c = "@C"; @d = "@D"; end
attr :c; attr :d
class Class_var
def init() @a = "A"; @b = "B"; end
attr :a; attr :b
end
end
c = "MAIN"
include M2
method_vars()
puts ">#{c}<--->#{d}<" # >MAIN<--->@D<
cv = Class_var.new
cv.init()
puts ">#{cv::a}<--->#{cv::b}<" # >A<--->B<
exit