(irb) a, b = 5
a => 5
b => nil
Shouldn't that be the other way around? What is actually happening here?
As I was writing this my coworker discovered why:
Ruby treats a, b = 5
as a, b = 5, nil
In Python3, a TypeError
is thrown.
In order to assign a value to b
using multiple assignment you'd have to give it a second value.
a, b = 5, 6
a = 5
b = 6
When you don't supply a second value, Ruby gives b
a value of nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With