I have a program like the following, where I the instances are declared
within the body of the program and I’d like to access ‘count’ in a
method of obj2, as indicated, but it doesn’t work.
I thought it might be because object one needed to be a global variable
but according to http://www.rubyist.net/~slagell/ruby/localvars.html
it’s scope would be the entire script anyway as it is not defined with a
block. I tried using $obj1 and $obj2 anyway but I can’t seem to refer to
$obj1.count within $obj2’s methods.
If I’m reading things right, class variables would be of no use either
in this situation. So, short of reading the value from obj1 first then
passing it as a parameter to obj2 is there another way?
#access One.count here
obj1 = One.new
obj2 = Two.new