From: Shashank Date Date: 2005-07-13T02:06:02+09:00 Subject: Re: Question: arrays v. ranges and *.each Hi David, --- David Douthitt wrote: > The results of the following code just seem strange to me: > > print "\nTry 1:" > print [1..10].class, "\n" > [1..10].each { |x| print x, "\n" } You are mixing two things here: a range and an array. [1..10] is an array of one object (1..10) which is an instance of the Range class. > print "\nTry 2:" > print [1..10].pop.class, "\n" > [1..10].pop.each { |x| print x, "\n" } so [1..10].pop gives (1..10). And Range itself is Enumerable. so: (1..10).each {|i| p i} is a valid construct. > I would have thought that either 1) try 1 would output a sequence of > numbers, and try 2 would result in an error (no such method > Integer#each); or, 2) try 1 would output a series of numbers and try 2 > would result in an error (no such method Range#pop). Perhaps - another > option would be 3) try 1 would result in '1..10' and try 2 would result > in something like '1..1' or an error? > > I'm confused... HTH, -- shanko ____________________________________________________ Sell on Yahoo! Auctions � no fees. Bid on great items. http://auctions.yahoo.com/