From: Christian Neukirchen Date: 2007-01-24T05:00:03+09:00 Subject: Re: Minor Change Proposal for Classes 'Object' and 'Method' "Phrogz" writes: > gwtmp01@mac.com wrote: >> On Jan 22, 2007, at 1:55 PM, Christian Neukirchen wrote: >> > While we are at it, can we please have UnboundMethod#to_proc? >> > It would greatly help to implement callbacks from class methods. >> >> This doesn't make sense. Without an object bound to the method >> 'self' will be undefined and so it is nonsensical to try to execute >> the associated code. > > Only if the method relies on the 'self'. For example: > > class Foo > def self.square( x ) > x*x > end > end > > could be reasonably translated to a lambda of: > > square = lambda{ |x| x*x } > > (I personally don't have a use case, but its certainly possible in some > scenarios.) Let me try to remember it... I actually grepped the logs: Dec 08 14:14:05 i want to use ordinary ruby modules as a mean to extend a lambda based object system Anyway, the case was I had a callback that was a module method, and I wanted an easy way to turn it into a proc. irb(main):001:0> module M; def foo; "foo!"; end; end => nil irb(main):002:0> M.instance_method(:foo) => # I imagine this to be useful for building DSLs, bundling callbacks etc, too? At least, allow binding unbound methods to nil without raising... that would make the not-existing self explicit, too: irb(main):004:0> M.instance_method(:foo).bind(nil) TypeError: bind argument must be an instance of M -- Christian Neukirchen http://chneukirchen.org