From: Sm sm Date: 2012-05-14T23:17:14+09:00 Subject: Re: Accessing child variables Jeremy W. wrote in post #1060687: > I would recommend reading a good book on Ruby to understand how > attr_accessor and instance variables work. I'd also use more descriptive > names when you're trying to learn these concepts. It's much easier to > program when thinking in terms of Cars containing Wheels with Tyres, > that it is A with a B, and a objC etc. > > http://pragprog.com/book/ruby3/programming-ruby-1-9 if a good place to > start. > > The code below works. Good luck! > > class A > attr_accessor :valA > end > > class B > attr_accessor :myarray > > def initialize > @myarray = [] > end > end > > class My_top > attr_accessor :c > > def initialize > objA = A.new > objA.valA = 10 > > @c = B.new > @c.myarray << objA > end > end > > my_top = My_top.new > puts my_top.c.myarray.inspect Hi Jeremy Thats perfect. Thanks for your help. I will read through the suggested book. Many Thanks -- Posted via http://www.ruby-forum.com/.