On Fri, Oct 5, 2012 at 8:03 AM, ajay paswan <[email protected]> wrote: > Thanks Jan, > Its great to hear such a complete and to the point answer, thank you > again. People like you gives me confidence that, one day I can also be > an expert of ruby!
You still should remove class variables from your repertoire. Their scoping semantics is weird and - as this thread shows - they are not very well integrated. Better leave them alone. Example for the weird scoping: $ ruby /tmp/cv.rb B1 -1072888598: [1, 2] D1 -1072888598: [1, 2] D2 -1072888848: [2] B2 -1072888918: [1] D2 -1072888918: [1] $ cat /tmp/cv.rb class B1; (@@x ||= []) << 1; end class D1 < B1; (@@x ||= []) << 2; end class B1; printf "B1 %12d: %p\n", @@x.object_id, @@x end class D1; printf "D1 %12d: %p\n", @@x.object_id, @@x end class B2; end class D2 < B2; (@@x ||= []) << 2; end class D2; printf "D2 %12d: %p\n", @@x.object_id, @@x end class B2; (@@x ||= []) << 1; end class B2; printf "B2 %12d: %p\n", @@x.object_id, @@x end class D2; printf "D2 %12d: %p\n", @@x.object_id, @@x end 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
