I have the following ruby script ruby_test.rb in eclipse (DLTK/RUBY), which throws a compilation error and I am not able to run in eclipse. This makes sense since *arr should be the last parameter. But when I run it on command line ( ruby ruby_test.rb ) its runs fine. any idea why?
My installed ruby version is 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)
也许您在Eclipse上有一个旧版本的Ruby,在该版本上,最后一个参数必须是splat参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.