[Ironruby-core] Issues with Method#to_proc

Daniele Alessandri suppakilla at gmail.com
Sat Jan 10 08:06:28 EST 2009


Today I was writing some code which uses Method#to_proc but I've
encountered a few issues. The following line throws a

proc = 0.method(:to_s).to_proc

I took a look at the source code of the ToProc method of MethodOps and
there's a comment which states that creating Procs out of CLR methods
is basically not yet supported. OK, so it seems reasonable given that,
as far as I understand, built-in library methods actually are CLR
methods internally.

Now, what if I try to create procs out of methods defined in ruby?

class Fixnum
    alias :__to_s :to_s
    def to_s

proc = 0.method(:to_s).to_proc

The original Fixnum#to_s has been aliased and Fixnum#to_s now responds
to a method defined at runtime in ruby, but then I get the following

`to_proc': Unable to cast object of type
'System.Func`3[System.Object,IronRuby.Builtins.Proc,System.Object]' to
type 'IronRuby.Runtime.Calls.BlockCallTarget0'.
        from :0

This exception is raised in the Create method of BlockDispatcher.

Should I file a bug? Or is this totally expected to happen because
Method#to_proc is still incomplete / in its early stages (if so, the
reported issue could fall into this bug report http://is.gd/fazo)?

Daniele Alessandri

More information about the Ironruby-core mailing list