开发者

Does Ruby 1.8.7 head support 1.9-style hash literals?

开发者 https://www.devze.com 2023-02-24 07:14 出处:网络
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 standa

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消