I
Iain Barnett
This is the output from irb that shows ruby 1.9.1 doesn't like hash =
entries to be preceded by a comma, only ended by one:
myhash3 =3D {
:first =3D> "first",
:second =3D> "second"
}
{:first=3D>"first", :second=3D>"second"}
myhash3 =3D {
:first =3D> "first"
, :second =3D> "second"
}
SyntaxError: (irb):48: syntax error, unexpected ',', expecting '}'
, :second =3D> "second"
^
from /Library/Frameworks/Ruby.framework/Programs/irb:12:in =
`<main>'
I prefer to put my comma's at the front of a line as it makes a line =
easier and quicker to comment out (1 vs 2 lines and a lot less fiddly). =
Is this only-commas-at-the-end by design or did I miss something? I've =
tested this with a script and with irb.
Quick addendum, thought I'd test this for arrays too, and it's the same.
myarr =3D [ 1, 2, 3]
[1, 2, 3]
myarr2 =3D [
1,
2,
3
]
[1, 2, 3]
myarr3 =3D [
1
,2
,3
]
SyntaxError: (irb):58: syntax error, unexpected ',', expecting ']'
from /Library/Frameworks/Ruby.framework/Programs/irb:12:in =
`<main>'
Iain=
entries to be preceded by a comma, only ended by one:
myhash3 =3D {
:first =3D> "first",
:second =3D> "second"
}
{:first=3D>"first", :second=3D>"second"}
myhash3 =3D {
:first =3D> "first"
, :second =3D> "second"
}
SyntaxError: (irb):48: syntax error, unexpected ',', expecting '}'
, :second =3D> "second"
^
from /Library/Frameworks/Ruby.framework/Programs/irb:12:in =
`<main>'
I prefer to put my comma's at the front of a line as it makes a line =
easier and quicker to comment out (1 vs 2 lines and a lot less fiddly). =
Is this only-commas-at-the-end by design or did I miss something? I've =
tested this with a script and with irb.
Quick addendum, thought I'd test this for arrays too, and it's the same.
myarr =3D [ 1, 2, 3]
[1, 2, 3]
myarr2 =3D [
1,
2,
3
]
[1, 2, 3]
myarr3 =3D [
1
,2
,3
]
SyntaxError: (irb):58: syntax error, unexpected ',', expecting ']'
from /Library/Frameworks/Ruby.framework/Programs/irb:12:in =
`<main>'
Iain=