0

我在 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)
4

1 回答 1

2

Perhaps you have an old version of Ruby on eclipse, on which a splat argument had to be the last argument.

于 2016-07-09T06:16:33.853 回答