From: Daniel Finnie Date: 2008-04-15T08:49:43+09:00 Subject: Re: Deleting first lines of Array Anytime. To answer your next question, Ruby's objects have types, Ruby variables do not. A variable's type can change at any time: >> x = [] => [] >> x.class => Array >> x = 42 => 42 >> x.class => Fixnum So, @installedPackageList was an Array when you created it with @installedPackageList = [] but then was re-assigned to a completely different type with the call to readlines(). In languages like Java, if you do this: int x = 50; x = 40; The first value of x is 50, but that value is completely thrown away when you assign 40 to x. That's what happened in the example, but the type and value of the variable were changed. Dan On Mon, Apr 14, 2008 at 4:56 PM, Jo Ay wrote: > Daniel Finnie wrote: > > Hi, > > > > @installedPackageList is an IO object, not an array. You need to read > > its contents, convert it into an array, and then remove things > > (readlines does steps one and two at once): > > @InstalledPackageList = @InstalledPackageList.readlines[5..-1] > > daniel@daniel-desktop:~/lightconsolegem$ ri IO#readlines > > ----------------------------------------------------------- IO#readlines > > ios.readlines(sep_string=$/) => array > > ------------------------------------------------------------------------ > > Reads all of the lines in ios, and returns them in anArray. Lines > > are separated by the optional sep_string. If sep_string is nil, > > the rest of the stream is returned as a single record. The stream > > must be opened for reading or an IOError will be raised. > > > > f = File.new("testfile") > > f.readlines[0] #=> "This is line one\n" > > > > > > Dan > > Hi all, > and thanks for your fast reply! > > Sorry for the typo in the class name (before doing the post, I quickly > rewrote the code to make it more sane/readable). > > @Dan: that was the solution to my problem! > > I'm just a little bit confused. I thought that I declared > installedPackageList as an array in the constructor, and therefore > expected it to be used like an array. > > Is that a typical pitfall to ruby newbies? I think I'll have to use > reflection alot more. > > Cheers > Joey > -- > > > Posted via http://www.ruby-forum.com/. > >