hit counter

Timeline

My development logbook

Ruby Quirk?

Have absolutely zero knowledge of Ruby, although I am planning to learn more about this langauge since I started using Octopress.

Came across this code snippet in this tweet

The behavior does look a bit odd from a python prespective.

1
2
3
4
5
6
7
8
9
10
mbp002:~ me$ irb
2.0.0p195 :001 > 1,2
SyntaxError: (irb):1: syntax error, unexpected ',', expecting end-of-input
    from /Users/me/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'
2.0.0p195 :003 > x=1,y=2
 => [1, 2] 
2.0.0p195 :004 > x
 => [1, 2] 
2.0.0p195 :005 > y
 => 2 

Apparently it is treated like

1
>> x = [1, (y = 2)]