From: Dave Thomas Date: 2001-07-24T02:13:17+09:00 Subject: [ruby-talk:18360] Re: Newbie question: Data structures in Ruby. Erik writes: > > > currentpage.articles[2].elements[5].content = 'Hello world' > > > > > > I am not sure if or how I can realise this, could somebody > > > please give me a hint? > > > > You could use the wonderful new PerlValue package (available on the > > RAA) > > Thank you for your help, but do I really need a module to do > something simple as this? No. > > As the module name suggests, it kind of emulates Perl for this feature. > Isn't there an obvious Ruby kind of way to do this? Yes, but the way you wrote the original code was so reminiscent of the way you'd do it in Perl, I wrongly assumed a Perl-like solution would be convenient for you. Personally, I'd implement a Container class that gave me the application specific functionality I needed, and then have Page, articles, element either subclass or delegate to this. That way, I'd insulate myself from the underlying implementation, which would seem to me more flexible. I could store data in arrays, on disk, or in a database and nothing would change. The Ruby delegation library is wonderful for constructing this kind of thing. Regards Dave