From: Ash Date: 2007-03-16T09:20:06+09:00 Subject: Re: to_a On Mar 15, 8:07 pm, Corey Konrad <0...@hush.com> wrote: > how come this works: > > array = (1..8).to_a > puts array[1] > > but this does not: > > array = 1..8 > array.to_a > puts array[1] > > 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]