# To\_a

**URL:** <https://rubytalk.org/t/to-a/36199>\
**Category:** ruby-talk\
**Created:** [16 March 2007 00:07 UTC](https://rubytalk.org/t/to-a/36199 "2007-03-16T00:07:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://rubytalk.org/u/Corey)\
**Post date:** [16 March 2007 00:07 UTC](https://rubytalk.org/t/to-a/36199/1 "2007-03-16T00:07:57Z")

</div>

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 via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Ash1](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Ash1](https://rubytalk.org/u/Ash1)\
**Post date:** [16 March 2007 00:20 UTC](https://rubytalk.org/t/to-a/36199/2 "2007-03-16T00:20:06Z")

</div>

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]

> **···**
>
> 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/.

---

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://rubytalk.org/u/Corey)\
**Post date:** [16 March 2007 00:33 UTC](https://rubytalk.org/t/to-a/36199/3 "2007-03-16T00:33:39Z")

</div>

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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Alex\_Gutteridge](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alex\_Gutteridge](https://rubytalk.org/u/Alex_Gutteridge)\
**Post date:** [16 March 2007 00:46 UTC](https://rubytalk.org/t/to-a/36199/4 "2007-03-16T00:46:58Z")

</div>

I think you understand fine, just take your time and take each step in turn. As you say, the code below works:

array = (1..8).to\_a  
puts array[1]

This makes a Range object from '(1..8)' and converts it to an Array using '.to\_a'. This array is assigned to the variable 'array' and you can access it as normal.

The code below doesn't work:

array = 1..8  
array.to\_a  
puts array[1]

This makes a Range object from '1..8' and assigns it to 'array'. You then create a new Array using 'array.to\_a' but do not assign it to anything ('array' is still a Range). This means the final statement doesn't work.

From your second post it looks like you tried:

array = 1..8.to\_a  
puts array[1]

This doesn't work because you are asking for a Range constructed from '1' to '8.to\_a'. I.e a Range from the Integer 1 to the Array '[8]'. This is an invalid Range. The parentheses in the first example ensure that the Range is constructed first and then the '.to\_a' method is called on that. Essentially the method call '.to\_a' takes precedence over the Range operator '..'.

Hope that helps.

Alex Gutteridge

Bioinformatics Center  
Kyoto University

> **···**
>
> On 16 Mar 2007, at 09:33, Corey Konrad wrote:
> 
> > 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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Biedenharn1](https://rubytalk.org/u/Rob_Biedenharn1)\
**Post date:** [16 March 2007 00:49 UTC](https://rubytalk.org/t/to-a/36199/5 "2007-03-16T00:49:22Z")

</div>



---

<div class="post-metadata">

**Author:** ![Ash1](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Ash1](https://rubytalk.org/u/Ash1)\
**Post date:** [16 March 2007 01:10 UTC](https://rubytalk.org/t/to-a/36199/6 "2007-03-16T01:10:08Z")

</div>

You're getting closer. It's correct that #to\_a does not transform the  
range into an array. In Ruby, methods that change the object they're  
called on are usually marked with a !, like #sort! on Array (sorts the  
array in place) or #capitalize! on String (uppercases the first letter  
in place). Otherwise you can usually expect to get a new object back.

Here's a snippet that uses () to build the array but still doesn't  
work:

array = (1..8) # Create a Range object, give it the name "array"  
array.to\_a # Call the method "to\_a" on the Range, get back an  
Array, but  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# don't put it anywhere  
puts array[1] # Message not understood, because "array" is the  
original Range.

It just occurred to me that you might also be confused about what's  
happening in the  
first line of your working example.

array = (1..8).to\_a

The assignment to "array" is done \_last\_. So this reads as "Create a  
new Range from 1 to 8, send it the message 'to\_a', then store the  
result of all of that in 'array'", not "Create a new Range from 1 to  
8, store that in 'array', then send it the message 'to\_a'".

Just out of curiosity, is this your first programming language, or if  
not what is your background? The issues you're encountering are  
things that you'll run into in many languages, Ruby just isn't quite  
as verbose in having them 🙂

> **···**
>
> On Mar 15, 8:33 pm, Corey Konrad \<0...@hush.com\> wrote:
> 
> > 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 viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://rubytalk.org/u/Corey)\
**Post date:** [16 March 2007 00:57 UTC](https://rubytalk.org/t/to-a/36199/7 "2007-03-16T00:57:43Z")

</div>

Alex Gutteridge wrote:

> > > The issue isn't with the parentheses, but with the behavior of the
> > 
> > language but it seems pretty difficult.
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> I think you understand fine, just take your time and take each step  
> in turn. As you say, the code below works:
> 
> array = (1..8).to\_a  
> puts array[1]
> 
> This makes a Range object from '(1..8)' and converts it to an Array  
> using '.to\_a'. This array is assigned to the variable 'array' and you  
> can access it as normal.
> 
> The code below doesn't work:
> 
> array = 1..8  
> array.to\_a  
> puts array[1]
> 
> This makes a Range object from '1..8' and assigns it to 'array'. You  
> then create a new Array using 'array.to\_a' but do not assign it to  
> anything ('array' is still a Range). This means the final statement  
> doesn't work.
> 
> From your second post it looks like you tried:
> 
> array = 1..8.to\_a  
> puts array[1]
> 
> This doesn't work because you are asking for a Range constructed from  
> '1' to '8.to\_a'. I.e a Range from the Integer 1 to the Array '[8]'.  
> This is an invalid Range. The parentheses in the first example ensure  
> that the Range is constructed first and then the '.to\_a' method is  
> called on that. Essentially the method call '.to\_a' takes precedence  
> over the Range operator '..'.
> 
> Hope that helps.
> 
> Alex Gutteridge
> 
> Bioinformatics Center  
> Kyoto University

ok, yeah now i understand why the () are there i just didnt see that for  
some reason.

See when i tried

> array = 1..8  
> array.to\_a  
> puts array[1]

my view was that i was creating a range and assigning it to array and  
then taking that range in array and converting it to an array by using  
array.to\_a. I had no idea i was just creating a new array there is no  
way to tell that from looking at it for me even now, to me that code  
looks like i am transforming the range stored in array... into an array.  
My view was that array.to\_a meant, take the range stored in array and  
convert it to an array but that isnt what its doing its just converting  
the variable array into an empty array? I dont know i still feel like i  
am missing something that is going on behind the scenes, learning ruby  
as a first programming language kind of seems like learning short hand  
english first instead of becoming fluent in english grammer.

> **···**
>
> > On 16 Mar 2007, at 09:33, Corey Konrad wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://rubytalk.org/u/Corey)\
**Post date:** [16 March 2007 01:15 UTC](https://rubytalk.org/t/to-a/36199/8 "2007-03-16T01:15:56Z")

</div>

Ash wrote:

> **···**
>
> > On Mar 15, 8:33 pm, Corey Konrad \<0...@hush.com\> wrote:
> > 
> > > \> The issue isn't with the parentheses, but with the behavior of the  
> > > \> array = 1..8  
> > > --  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > You're getting closer. It's correct that #to\_a does not transform the  
> > range into an array. In Ruby, methods that change the object they're  
> > called on are usually marked with a !, like #sort! on Array (sorts the  
> > array in place) or #capitalize! on String (uppercases the first letter  
> > in place). Otherwise you can usually expect to get a new object back.
> > 
> > Here's a snippet that uses () to build the array but still doesn't  
> > work:
> > 
> > array = (1..8) # Create a Range object, give it the name "array"  
> > array.to\_a # Call the method "to\_a" on the Range, get back an  
> > Array, but  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# don't put it anywhere  
> > puts array[1] # Message not understood, because "array" is the  
> > original Range.
> > 
> > It just occurred to me that you might also be confused about what's  
> > happening in the  
> > first line of your working example.
> > 
> > array = (1..8).to\_a
> > 
> > The assignment to "array" is done \_last\_. So this reads as "Create a  
> > new Range from 1 to 8, send it the message 'to\_a', then store the  
> > result of all of that in 'array'", not "Create a new Range from 1 to  
> > 8, store that in 'array', then send it the message 'to\_a'".
> > 
> > Just out of curiosity, is this your first programming language, or if  
> > not what is your background? The issues you're encountering are  
> > things that you'll run into in many languages, Ruby just isn't quite  
> > as verbose in having them 🙂
> 
> My background i have a degree in computer information systems and have  
> been studying things like this for going on 4 years now, i got a 3.12  
> gpa in school and i have studied the syntax of many languages but for  
> some reason i just cant ever seem to get anywhere with it, its getting  
> really frustrating and i am starting to think that maybe i am mentally  
> retarded literally.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [16 March 2007 01:05 UTC](https://rubytalk.org/t/to-a/36199/9 "2007-03-16T01:05:40Z")

</div>

I think more familiarity with object oriented programming concepts may  
help you sort these things out. Even though from a non-OOP background  
it may look like array.to\_a is doing something to the array variable,  
it's not. The .to\_a in that is a "message" you send to the object,  
"array". That object, then, does "to\_a". It doesn't change itself --  
it just uses "to\_a" to give you an array version of itself.

In other words, "array" doesn't "change to a", it emits "to a", which  
you can then capture somewhere.

Think of objects, generally speaking, as immutable things that do stuff  
for you when you ask nicely. You can get around that with the  
assignment operator and bang-punctuated methods, but in general you're  
not changing the object. Instead, you're getting it to give you  
something.

That's oversimplified in the extreme, and prone to error if taken too  
literally, but in general that's why .to\_a gives you a return value  
rather than changing the object. Interestingly, this philosophy of OOP  
also overlaps somewhat with the functional programming paradigm, which  
is why many people think of Ruby as an excellent language as a stepping  
stone to more-pure functional programming languages.

> **···**
>
> On Fri, Mar 16, 2007 at 09:57:43AM +0900, Corey Konrad wrote:
> 
> > See when i tried
> > 
> > \> array = 1..8  
> > \> array.to\_a  
> > \> puts array[1]
> > 
> > my view was that i was creating a range and assigning it to array and  
> > then taking that range in array and converting it to an array by using  
> > array.to\_a. I had no idea i was just creating a new array there is no  
> > way to tell that from looking at it for me even now, to me that code  
> > looks like i am transforming the range stored in array... into an array.  
> > My view was that array.to\_a meant, take the range stored in array and  
> > convert it to an array but that isnt what its doing its just converting  
> > the variable array into an empty array? I dont know i still feel like i  
> > am missing something that is going on behind the scenes, learning ruby  
> > as a first programming language kind of seems like learning short hand  
> > english first instead of becoming fluent in english grammer.
> 
> --  
> CCD CopyWrite Chad Perrin [[http://ccd.apotheon.org](http://ccd.apotheon.org) ]  
> "The ability to quote is a serviceable  
> substitute for wit." - W. Somerset Maugham

---

<div class="post-metadata">

**Author:** ![Alex\_Gutteridge](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alex\_Gutteridge](https://rubytalk.org/u/Alex_Gutteridge)\
**Post date:** [16 March 2007 01:10 UTC](https://rubytalk.org/t/to-a/36199/10 "2007-03-16T01:10:24Z")

</div>

> Alex Gutteridge wrote:

[snip!]

> See when i tried
> 
> > array = 1..8  
> > array.to\_a  
> > puts array[1]
> 
> my view was that i was creating a range and assigning it to array and  
> then taking that range in array and converting it to an array by using  
> array.to\_a. I had no idea i was just creating a new array there is no  
> way to tell that from looking at it for me even now, to me that code  
> looks like i am transforming the range stored in array... into an array.  
> My view was that array.to\_a meant, take the range stored in array and  
> convert it to an array but that isnt what its doing its just converting  
> the variable array into an empty array?

Not quite. It's converting the Range to an Array and giving it to you, but you don't tell it to do anything with the new Array.

array = array.to\_a

is what you're missing here. Almost all standard Ruby methods work this way unless you see one with a '!' in the method name. They are 'non-destructive', so they don't effect the object you call them on. Instead, they give you a new object. For example, the 'compact' and compact!' methods in the Array class both remove nil elements from an Array, but they work slightly differently. Compare:

arr = [1,nil,2,3]  
arr.compact  
puts arr[1]

with

arr = [1,nil,2,3]  
arr.compact!  
puts arr[1]

Alex Gutteridge

Bioinformatics Center  
Kyoto University

> **···**
>
> On 16 Mar 2007, at 09:57, Corey Konrad wrote:

---

<div class="post-metadata">

**Author:** ![Harry4](https://avatars.discourse-cdn.com/v4/letter/h/c2a13f/32.png) [@Harry4](https://rubytalk.org/u/Harry4)\
**Post date:** [16 March 2007 01:19 UTC](https://rubytalk.org/t/to-a/36199/11 "2007-03-16T01:19:39Z")

</div>

> ok, yeah now i understand why the () are there i just didnt see that for  
> some reason.
> 
> See when i tried
> 
> \> array = 1..8  
> \> array.to\_a  
> \> puts array[1]
> 
> my view was that i was creating a range and assigning it to array and  
> then taking that range in array and converting it to an array by using  
> array.to\_a. I had no idea i was just creating a new array there is no  
> way to tell that from looking at it for me even now, to me that code  
> looks like i am transforming the range stored in array... into an array.  
> My view was that array.to\_a meant, take the range stored in array and  
> convert it to an array but that isnt what its doing its just converting  
> the variable array into an empty array? I dont know i still feel like i  
> am missing something that is going on behind the scenes, learning ruby  
> as a first programming language kind of seems like learning short hand  
> english first instead of becoming fluent in english grammer.

Maybe using the variable name 'array' is tricking you into thinking it  
actually is an array.  
Try changing the variable name, look at the code and think about the  
explanation that Alex gave you.

Try this.

#foo = 1..8  
#foo.to\_a  
#puts foo[1]

foo = 1..8  
p foo  
x = foo.to\_a  
p x  
puts x[1]

Harry

> **···**
>
> --
> 
> > **[Kakueki.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=kakueki.com)**
> >
> > Start using this domain right away. Straightforward domain shopping experience. Quick access to your domain.
> 
> Japanese Ruby List Subjects in English

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [16 March 2007 01:31 UTC](https://rubytalk.org/t/to-a/36199/12 "2007-03-16T01:31:40Z")

</div>

My favorite programming teacher in high school had a saying he probably used daily, "Man I hate computers." 😉

It's really a different way of thinking that takes some getting use to. Don't be too hard on yourself. We all went through this adjustment period.

James Edward Gray II

> **···**
>
> On Mar 15, 2007, at 8:15 PM, Corey Konrad wrote:
> 
> > Ash wrote:
> > 
> > > On Mar 15, 8:33 pm, Corey Konrad \<0...@hush.com\> wrote:
> > > 
> > > > > The issue isn't with the parentheses, but with the behavior of the  
> > > > > array = 1..8
> > > > 
> > > > --  
> > > > Posted viahttp://www.ruby-forum.com/.
> > > 
> > > You're getting closer. It's correct that #to\_a does not transform the  
> > > range into an array. In Ruby, methods that change the object they're  
> > > called on are usually marked with a !, like #sort! on Array (sorts the  
> > > array in place) or #capitalize! on String (uppercases the first letter  
> > > in place). Otherwise you can usually expect to get a new object back.
> > > 
> > > Here's a snippet that uses () to build the array but still doesn't  
> > > work:
> > > 
> > > array = (1..8) # Create a Range object, give it the name "array"  
> > > array.to\_a # Call the method "to\_a" on the Range, get back an  
> > > Array, but  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# don't put it anywhere  
> > > puts array[1] # Message not understood, because "array" is the  
> > > original Range.
> > > 
> > > It just occurred to me that you might also be confused about what's  
> > > happening in the  
> > > first line of your working example.
> > > 
> > > array = (1..8).to\_a
> > > 
> > > The assignment to "array" is done \_last\_. So this reads as "Create a  
> > > new Range from 1 to 8, send it the message 'to\_a', then store the  
> > > result of all of that in 'array'", not "Create a new Range from 1 to  
> > > 8, store that in 'array', then send it the message 'to\_a'".
> > > 
> > > Just out of curiosity, is this your first programming language, or if  
> > > not what is your background? The issues you're encountering are  
> > > things that you'll run into in many languages, Ruby just isn't quite  
> > > as verbose in having them 🙂
> > 
> > My background i have a degree in computer information systems and have  
> > been studying things like this for going on 4 years now, i got a 3.12  
> > gpa in school and i have studied the syntax of many languages but for  
> > some reason i just cant ever seem to get anywhere with it, its getting  
> > really frustrating and i am starting to think that maybe i am mentally  
> > retarded literally.

---

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://rubytalk.org/u/Corey)\
**Post date:** [16 March 2007 01:42 UTC](https://rubytalk.org/t/to-a/36199/13 "2007-03-16T01:42:33Z")

</div>

James Gray wrote:

> > > called on are usually marked with a !, like #sort! on Array (sorts  
> > > array.to\_a # Call the method "to\_a" on the Range, get back an
> > 
> > My background i have a degree in computer information systems and have  
> > been studying things like this for going on 4 years now, i got a 3.12  
> > gpa in school and i have studied the syntax of many languages but for  
> > some reason i just cant ever seem to get anywhere with it, its getting  
> > really frustrating and i am starting to think that maybe i am mentally  
> > retarded literally.
> 
> My favorite programming teacher in high school had a saying he  
> probably used daily, "Man I hate computers." 😉
> 
> It's really a different way of thinking that takes some getting use  
> to. Don't be too hard on yourself. We all went through this  
> adjustment period.
> 
> James Edward Gray II

yeah i suppose, man i cant imagine learning C or assmembler or something  
like that. i think i get this issue now though methods arent destructive  
so i am not transforming the range object i am returning a new array  
object and i have to put it someplace in order to use it. I think that  
makes sense now.

Thanks alot for the help you guys i appreciate it, believe me there are  
more questions coming lol.

> **···**
>
> > On Mar 15, 2007, at 8:15 PM, Corey Konrad wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)\
**Post date:** [16 March 2007 12:10 UTC](https://rubytalk.org/t/to-a/36199/14 "2007-03-16T12:10:53Z")

</div>

It also of course depends on the method. That is why everyone said "most of the time"...  
It is possible to write your own code where a method call/message could actually change the reciever object.  
It just isn't usual in Ruby.  
Also do understand that methods are often oversimplified in human language.  
The truth is, we "send a message" to an object. The object is the "reciever". If the object knows what to do with that message (if it has the method inside) it will do it. Otherwise the Ruby interpreter (the runtime environment in any OOP language) will move up the responder chain, to the object's parent class/super class. We say it sends the message there. The message will continue being sent until it reaches the root object class or finds a responder.  
Some of the specifics are different with different languages, and it can get pretty abstract, but it is always the same.
