[Ironruby-core] Issues with Method#to_proc

Tomas Matousek Tomas.Matousek at microsoft.com
Sat Jan 10 12:24:14 EST 2009

Could you please add your comment to bug #20297?


-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Daniele Alessandri
Sent: Saturday, January 10, 2009 5:06 AM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] Issues with Method#to_proc


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
Ironruby-core mailing list
Ironruby-core at rubyforge.org

More information about the Ironruby-core mailing list