I'm responsible for maintaining a legacy Ruby on Rails application, and I'm currently testing it on Ruby v1.8.7 (2013-12-22 patchlevel 375). The app is using Rails v3.2.22.1 (a Rails version provided by Rails LTS). I am bumping into a weird syntax issue.
In a vanilla IRB console, the hash rocket syntax for a Hash works as expected, and the JSON syntax for raises a syntax error as expected. However, in a Rails console, the JSON syntax is working just fine, and I can't figure out why it's NOT raising a syntax error.
Any ideas what is going on in the code below?
# in Bash
$ ruby -v
ruby 1.8.7 (2013-12-22 patchlevel 375) [i686-darwin18.2.0]
# in Rails console
Loading development environment (Rails 3.2.22.1)
irb(main):001:0> system "ruby -v"
ruby 1.8.7 (2013-12-22 patchlevel 375) [i686-darwin18.2.0]
=> true
irb(main):002:0> {a: 1} # JSON syntax doesn't trigger SyntaxError
=> {:a=>1}
# loading vanilla IRB *()
irb(main):003:0> system "irb" # loading vanilla IRB
# in vanilla IRB (via Rails console, if that matters)
irb(main):001:0> system "ruby -v"
ruby 1.8.7 (2013-12-22 patchlevel 375) [i686-darwin18.2.0]
=> true
irb(main):002:0> {a: 1} # expected syntax error
SyntaxError: compile error
(irb):2: odd number list for Hash
{a: 1}
^
(irb):2: syntax error, unexpected ':', expecting '}'
{a: 1}
^
from (irb):2
Aucun commentaire:
Enregistrer un commentaire