2010-09-02 79 views
0

我正在研究IronRuby中的一些東西,但我遇到了一些障礙。這個代碼塊:IronRuby對each_for_index有問題嗎?

def func 
    b = @b 
    b.each_with_index do |element, index| 
     <some stuff in here> 
    end 
end 

提供了以下錯誤:

./myfile.rb:<line number>:in 'func': wrong number of arguments (0 for 1) (ArgumentError) 
    from IronRuby.Libraries:0:in '<EachWithIndex>b__9' 
    from IronRuby.Libraries:0:in 'each' 
    from IronRuby.Libraries:0:in 'Each' 
    from ./myfile.rb:<line number>:in 'each_with_index' 
    from ./myfile.rb:<line number>:in 'func' 

難道我做錯了什麼嗎?我正在使用IronRuby 1.0(.NET 2.0版本)。這可能顯得很荒唐,但我一直無法找到答案。

作爲一個說明:我已經在那裏拋出了一堆put語句,而b肯定是一個Array,所以它不像我試圖對它不應該工作的東西做這件事。

回答

1

啊,我明白了,IronRuby的目標是Ruby 1.8.6,顯然each_for_index在1.8.6中沒有返回枚舉器。我已將其更改爲:

require 'enumerator' 

b.enum_for(:each_with_index) do |element, index| 

它似乎工作正常。