From: Corey Konrad <0011@...> Date: 2007-03-16T09:33:39+09:00 Subject: Re: to_a Ash wrote: > On Mar 15, 8:07 pm, Corey Konrad <0...@hush.com> wrote: >> >> what do the () in the above example do that makes it work? >> >> thanks >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > The issue isn't with the parentheses, but with the behavior of the > #to_a method. #to_a does not modify its receiver. Instead, it builds > a new instance of Array and returns it. In the first example, you're > capturing the return value of #to_a and assigning it to the variable > "array". In the second, you're assigning a Range to the variable > "array", calling #to_a on it, and tossing the Array you get back on > the floor. > > To make the second example work properly, you need to capture the > return value in a new variable and use that instead: > > array = 1..8 > result = array.to_a > puts result[1] i am not sure if i understand...so to_a doesnt actually transform the range into an array it just creates a new array object. That still doesnt explain why the first one using the () works though when i remove the () it doesnt work. I dont know this stuff is really confusing. I started learning ruby because i heard it was an easy and intuitive language but it seems pretty difficult. -- Posted via http://www.ruby-forum.com/.