From: James Edward Gray II Date: 2007-03-16T10:31:40+09:00 Subject: Re: to_a 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 >> # 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. 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