From: Pokkai Dokkai Date: 2008-01-29T21:18:02+09:00 Subject: Re: can you do this ? ruby aptitute Luc Heinrich wrote: > On 29 janv. 08, at 10:47, Pokkai Dokkai wrote: > >> how to pass @aa(in C2) value to @bb(in C1) ? >> @aa is a dynamic value > > I first tried with various uses of Binding but couldn't get it to work. > > This super-ugly hack works though; > > # in source1.rb > class C2; end > class C1 > def met > ObjectSpace.each_object(C2) { |o| @bb = o.instance_variable_get > (:@aa) } > puts @bb > end > end nice answer i tried many times but i can't i got some confusing about this oops concept. is there anyway to get the "current parent object instance variable" in "child object instance variable" ? for example in above problem like class C2 def initialize(aa) @aa=aa end def met C1.new.met end end obj1=C2.new(1) obj2=C2.new(2) obj3=C2.new(3) obj1.met --> 1 obj2.met --> 1 obj3.met --> 1 but the answer should be like obj1.met ---> 1 obj2.met ---> 2 obj3.met ---> 3 do you have any idea to get like this answer ? --------------------- i have one more doublt if there is a object "parent_obj".It may be any type of Class ( not C2 only ). now assign parent_obj.aa=10 inside "parent_obj" have a "child_obj" ( like this parent_obj.child_obj ) now how to assign (aa=10) into parent_obj.child_obj.bb this can be done as you told . but that is for some particular class only for example like C2 ( ObjectSpace.each_object(C2) ) thank you -- Posted via http://www.ruby-forum.com/.