# Issues with Method#to\_proc

**URL:** <https://www.ruby-forum.com/t/issues-with-method-to-proc/157391>\
**Category:** IronRuby\
**Created:** [January 10, 2009, 2:17pm UTC](https://www.ruby-forum.com/t/issues-with-method-to-proc/157391 "2009-01-10T14:17:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [January 10, 2009, 2:17pm UTC](https://www.ruby-forum.com/t/issues-with-method-to-proc/157391/1 "2009-01-10T14:17:51Z")

</div>

Hello,

Today I was writing some code which uses Method#to\_proc but I’ve  
encountered a few issues. The following line throws a  
NotImplementedException:

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  
self.\_\_to\_s  
end  
end

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  
InvalidCastException:

C:\Sviluppo\ironruby\SVN\trunk\src\IronRuby.Libraries\Builtins\MethodOps.cs:63:in  
`to_proc': Unable to cast object of type 'System.Func`3[System.Object,IronRuby.Builtins.Proc,System.Object]’ to  
type ‘IronRuby.Runtime.Calls.BlockCallTarget0’.  
(System::InvalidCastException)  
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](http://is.gd/fazo))?

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [January 10, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/issues-with-method-to-proc/157391/2 "2009-01-10T18:49:26Z")

</div>

Could you please add your comment to bug #20297?

Thanks,  
Tomas
