On Sat, Dec 15, 2012 at 6:15 PM, Michael Sas <[email protected]> wrote: > Hi, > > i have a circular reference between two classes. Initialize of one needs > the other. Small example: > > A.new b_instance > B.new a_instance > > So I thought I could do: > > a = A.new nil > b = B.new a > a = A.new B > > The attached valuedemo.rb contains a executable example of how i tried > to do and shows the problem. It also showes where i get confused about > call by value or call by reference. > > As I understand param in the example is not equal but the same to > @param. So param and @param are references to the same object, rather > identical copies of an object. So if the value changes in one place, it > should change every where.
No. It's: if the object changes the change is visible in all locations which reference it. There is no call by reference in Ruby. > It doesn't, so its clear my understanding is wrong. > > I would be happy about general advice on solving circular references > too. > > Attachments: > http://www.ruby-forum.com/attachment/7971/valuedemo.rb You initialize instance of A with nil. The object reference contained in "param" is copied so @param still references nil when you update "param" to point to 2. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
