From: Robert Nicholson Date: 2006-05-15T09:50:44+09:00 Subject: Re: begining programmer questions Yeah isn't everything a first class object in Ruby. Looked to me as though the issue was the scope since he originally declared it in the def rather than in the scope of the caller where he wants to refer to it. On May 14, 2006, at 5:20 PM, Michael Gorsuch wrote: > I suppose it could, but I think the easiest way to build an Array > in ruby is > as follows: > > info = [] > > You can build a Hash via: > > info = {} > > On 5/14/06, corey konrad <0011@hush.com> wrote: >> >> i dont know doing info = Array.new seems like an array declaration to >> me. Couldn the constrution of an array object be implied in just >> saying >> info[] you what what i mean? That would be even more simplified. >> >> >> >> corey konrad wrote: >> > oh ok thats right it has to be an object in order to be useful. >> The book >> > i am reading didnt mention that in the entire chapter on arrays. >> thats >> > why i didnt get it. >> > >> > >> > >> > Michael Gorsuch wrote: >> >> When you call 'info[]', the '[]' piece is actually trying to >> invoke a >> >> method >> >> in the object. >> >> >> >> since 'info' is not delcared as an object, Ruby has no clue >> what to do. >> >> >> >> Now, if you did this: >> >> >> >> info = [] >> >> >> >> or >> >> >> >> info = Array.new >> >> >> >> You'd be better off. >> >> >> >> As for stuffing 'info' with data, you can do this: >> >> >> >> info << gets.comp >> >> >> >> and >> >> >> >> info.sort! >> >> >> >> Does this help you at al >> >> >> -- >> Posted via http://www.ruby-forum.com/. >> >>