ruby-1.8.7-p174 :001 > SOMETHING = 2355, SOMETHING2 = 3453
=> [2355, 3453]
Why?
ruby-1.8.7-p174 :001 > SOMETHING = 2355, SOMETHING2 = 3453
=> [2355, 3453]
Why?
On Feb 9, 2012, at 8:03 PM, Daniel W. wrote:
ruby-1.8.7-p174 :001 > SOMETHING = 2355, SOMETHING2 = 3453
=> [2355, 3453]Why?
It gets parsed as:
SOMETHING = [ 2355, (SOMETHING2 = 3453) ]
-Rob
On Thu, Feb 9, 2012 at 7:03 PM, Daniel W. [email protected]
wrote:
ruby-1.8.7-p174 :001 > SOMETHING = 2355, SOMETHING2 = 3453
=> [2355, 3453]Why?
Because of how multiple assignment and destructuring work, the RHS will
be
treated like an array
a = 1, 2 # => [1, 2]
Now this particular assignment has an assignment in the RHS, which is
treated like this.
SOMETHING = 2355, SOMETHING2 = 3453
SOMETHING = 2355, (SOMETHING2 = 3453)
SOMETHING = 2355, 3453
For correct multiple assignment, it would be
SOMETHING, SOMETHING2 = 2355, 3453
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs