【问题标题】:ruby splat operator compilation error in eclipse but runs fine on command lineEclipse 中的 ruby​​ splat 运算符编译错误,但在命令行上运行良好
【发布时间】:2016-11-11 17:56:11
【问题描述】:

我在 Eclipse (DLTK/RUBY) 中有以下 ruby​​ 脚本 ruby_test.rb,它会引发编译错误,我无法在 eclipse 中运行。这是有道理的,因为 *arr 应该是最后一个参数。但是当我在命令行 (ruby ruby​​_test.rb) 上运行它时,它运行良好。知道为什么吗?

我安装的 ruby​​ 版本是 2.1.6p336

#!/usr/bin/ruby

arr = [1,2,3]

def test(a1,a2,a3,a4,a5)
   puts "The first number  is #{a1}"
   puts "The second number is #{a2}"
end

test(0, *arr, 4)

【问题讨论】:

  • 可能是不同的解释器。官方的 Ruby 允许像这样的 IIRC

标签: ruby eclipse variadic-functions splat dltk


【解决方案1】:

也许您在 Eclipse 上有一个旧版本的 Ruby,在该版本上,splat 参数必须是最后一个参数。

【讨论】:

  • 我在 Eclipse 首选项中使用“/Users/north/.rvm/rubies/ruby-2.1.6/bin/ruby”作为 ruby​​ 解释器的解释器可执行文件。我可能缺少任何其他设置吗?
  • 我确认通过使用 ` puts RUBY_VERSION ` 编写一个 1 行脚本,这会导致输出 2.1.6
  • 您的 Eclipse 设置肯定有问题或过时。
猜你喜欢
  • 2017-04-16
  • 2011-12-11
  • 1970-01-01
  • 2011-06-18
  • 2017-07-23
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
  • 2019-05-01
相关资源
最近更新 更多