Take the 2-minute tour ×

I'm working on some stuff in IronRuby, but I've run into a bit of a snag. This chunk of code:

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

gives the following error:

./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'

Am I doing anything wrong here? I'm using IronRuby 1.0 (the .NET 2.0 version). It's probably something ridiculously obvious, but I just haven't been able to find the answer.

As a note: I've thrown a bunch of puts statements in there, and b is definitely an Array, so it's not like I'm trying to do this on something it shouldn't work on.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Ah, I figured it out, IronRuby targets Ruby 1.8.6, and apparently each_for_index didn't return an enumerator in 1.8.6. I've changed it to:

require 'enumerator'

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

and it seems to work fine.

share|improve this answer
add comment

Your Answer


