April 2010
1 post
4 tags
How a little comma in ruby code can be a pain in...
Let assume that you transform a hash
{
:a => 1,
:b => 2
}
into local variables somewhere in your code and forget to remove a little comma after one line
a = 1,
b = 2
You still have a valid ruby code but it produces something unexpected!
a # => [1,2]
b # => 2
Why? Because of the comma ruby uses multiple assignment operator to assign values. Let write the code into one line to...