From: Julian Leviston Date: 2009-02-04T16:17:37+09:00 Subject: Re: Method.new - why not? Isn't that how it already works?? :). Sorta. :). Try this: File.method(:foreach) Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 04/02/2009, at 5:20 PM, Daniel Berger wrote: > Hi, > > Just a random thought that I think was inspired by several people on > the list asking about getting the name of the method from within the > method - why don't we have Method.new? In other words, what if this: > > def foo(x, y=1) > end > > Was the equivalent of this? > > x = Method.new(:name => 'foo', :parameters => ['x', 'y'], :defaults => > {'y' => 1}) > Object.include(x) # or bind(x) or something > > Similar to an UnboundMethod I suppose, but with more options. Wouldn't > it be easier to get method metadata with this approach? And give > programmers the ability to associate any methods with any class or > module? > > class Bar > def foo(x, y=1) > p method(:foo).metadata # => @name => 'foo', @parameters => > ['x','y'], :defaults => {'y' => 1}) > end > end > > Or is this totally stupid? > > If this has been discussed before just point me to the thread. > > Regards, > > Dan >