Help me understand this

I have my own theory, but I haven’t seen the implementation yet. Or
maybe it’s something simple, and I am just making things complicated.
Here goes:

-> irb
irb(main):001:0> b,c = 1,2
=> [1, 2]
irb(main):002:0> a = b,c = 1,2
=> [1, 1, 2]
irb(main):003:0> a
=> [1, 1, 2]
irb(main):004:0> a.inspect
=> “[1, 1, 2]”
irb(main):005:0> a.class
=> Array
irb(main):006:0>

From: Elpee Zit [mailto:[email protected]]
#…

this,

b,c = 1,2
=> [1, 2]
b
=> 1
c
=> 2

compare to this,

b,c = [1,2]
=> [1, 2]
b
=> 1
c
=> 2

then,

a = b,c = 1,2
=> [1, 1, 2]
a
=> [1, 1, 2]
b
=> 1
c
=> 1

compare

a = [b,(c = 1),2]
=> [1, 1, 2]
a
=> [1, 1, 2]
b
=> 1
c
=> 1

it’s an array all to the right…

Thank You !!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs