jruby-是ruby lambda语法->不是重要的考虑因素吗? [英] jruby - is ruby lambda syntax -> not an important consideration?
本文介绍了jruby-是ruby lambda语法->不是重要的考虑因素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到,即使最新的1.6.4 jruby版本也不支持Ruby 1.9中的新lambda语法->.因此,我猜想这种语法在ruby社区中并不常用.是因为语法是新的还是有其他缺点?
I noticed that new lambda syntax -> in Ruby 1.9 is not supported even in the latest 1.6.4 jruby release. So, I am guessing this syntax is not commonly used in the ruby community. Is it because the syntax is new or are there any other disadvantages?
x = -> y { y+1 }
x.call(2)
这在ruby 1.9.1中返回3,并在jruby 1.6.4中给出语法错误
This returns 3 in ruby 1.9.1 and gives a syntax error in jruby 1.6.4
推荐答案
您未在1.9模式下运行它.
You are not running it in 1.9 mode.
$ jruby --1.9 -S irb
irb(main):001:0> x = -> y { y+1 }
=> #<Proc:0x1e937f@(irb):1 (lambda)>
irb(main):002:0> x.call(2)
=> 3
这篇关于jruby-是ruby lambda语法->不是重要的考虑因素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文