[#927] UnboundMethod#to_proc — Dave Thomas <dave@...>

I'm wondering what I can do with a Proc generated by

17 messages 2003/04/06

Re: UnboundMethod#to_proc

From: matz@... (Yukihiro Matsumoto)
Date: 2003-04-06 10:51:23 UTC
List: ruby-core #928
Hi,

In message "UnboundMethod#to_proc"
    on 03/04/06, Dave Thomas <dave@thomases.com> writes:

|I'm wondering what I can do with a Proc generated by
|
|   UnboundMethod.to_proc

The error message gives what you can do:

 % ruby -e 'Kernel.instance_method(:printf).to_proc.call("foo")'
 -e:1:in `to_proc': you cannot call unbound method; bind first (TypeError)
        from -e:1:in `call'
        from -e:1

so, bind UnboundMethod first, then call to_proc.

 % ruby -e 'p Kernel.instance_method(:printf).bind(self).to_proc.call("foo")'
 foo

							matz.

In This Thread