[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Array assignment with multiple args

Yukihiro Matsumoto

5/15/2008 5:56:00 AM

Hi,

In message "Re: Array assignment with multiple args"
on Thu, 15 May 2008 04:20:35 +0900, Jeff Hales <qbass69@hotmail.com> writes:

|Hi all. I'm just starting to learn Ruby and have hit a problem that is
|being extremely difficult to find information on. When given a line of
|code such as:
|
|a = "this", b = "that", c = "those"
|
|Is there a concise and elegant way of describing why variable a is
|assigned as an array, but variable b is not? There must be a simple
|explanation as to 'why' this is happening. The only description of what
|is going on here that I have found is that this is interpreted as
|
|a = "this", (b = "that"), (c = "those")

More precisely,

a = ("this", (b = "that"), (c = "those"))

But I am not sure what you wanted to accomplish by

a = "this", b = "that", c = "those"

In Ruby, commas are not expression separator.

|and not
|
|a = "this", (b = "that", c = "those")
|
|and that the arguments are read from right to left. This hasn't really
|helped my understanding, as that much can be deduced just by putting the
|line through the Ruby interpreter, and I don't see how reading the
|assignments from right to left assigns ["this","that","those"] to
|variable a but only "that" to variable b.

Multiple assignment does not nest. Assignments in right hand side is
considered as normal assignments.

matz.