Does Ruby 1.8.7 head support 1.9-style hash literals?

北城以北 提交于 2019-12-11 12:19:58

问题


According to http://redmine.ruby-lang.org/issues/1183 , Ruby 1.9's {foo: 42} apparently was back-ported to Ruby 1.8. But I tried running ruby-1.8.7-head using RVM, and I got the standard syntax error:

Andrew-Grimms-MacBook-Pro:ruby agrimm$ rvm use ruby-1.8.7-head
Using /Users/agrimm/.rvm/gems/ruby-1.8.7-head
Andrew-Grimms-MacBook-Pro:ruby agrimm$ irb
ruby-1.8.7-head :001 > {a: "foo"}
SyntaxError: compile error
(irb):1: odd number list for Hash
{a: "foo"}
   ^
(irb):1: syntax error, unexpected ':', expecting '}'
{a: "foo"}
   ^
(irb):1: syntax error, unexpected '}', expecting $end
    from (irb):1

Has the change been reverted, or are not all changes to the source code reflected in ruby-1.8.7-head?


回答1:


Check the version number: this patch was applied to Ruby 1.8.8, not 1.8.7. Which ruby-core agreed just 4 days ago will never be released. As of last week, 1.8 is officially dead.

1.8.8 was the mythical transitional version that would correctly parse but not execute Ruby 1.9 syntax, so that you could write stuff like

if RUBY_VERSION > '1.8'
  ->x { x }
else
  lambda {|x| x }
end

However, it turned out that everybody who wanted to migrate to Ruby 1.9 was already doing so, and the people that didn't want to migrate would not have been swayed by 1.8.8, so it simply didn't make sense to divert any more resources to it.



来源:https://stackoverflow.com/questions/5620785/does-ruby-1-8-7-head-support-1-9-style-hash-literals

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!