Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RCR: def method...end return a method object.

0 views
Skip to first unread message

Roger Pack

unread,
Dec 31, 2009, 12:52:23 PM12/31/09
to
Currently if I want to "do something" to a method after it's defined, I
basically have to do

def method
# stuff
end
do_something_to_method :method

(or hook onto method_added).

This is surprising since typically with ruby constructs you can use them
as blocks, like

a.compact{}.uniq.whatever

Proposal:
Change def to return a Method instance [1]

which would allow construct like
def method

end.do_something_to_it

Feedbacks?
-r

[1] http://rcrchive.net/ the idea isn't new
--
Posted via http://www.ruby-forum.com/.

Ryan Davis

unread,
Dec 31, 2009, 2:39:24 PM12/31/09
to

On Dec 31, 2009, at 09:52 , Roger Pack wrote:

> Currently if I want to "do something" to a method after it's defined

#method always returns a copy of a method, not the original. Presumably def would have to do the same thing, rendering it a lot less useful. I'd rather it return the name defined as a symbol, but honestly I think that constructs like your example:

> def method
>
> end.do_something_to_it

are unclear. Constructs should generally do one thing only. In this case, define a method.

Phrogz

unread,
Jan 1, 2010, 10:24:45 PM1/1/10
to
On Dec 31 2009, 10:52 am, Roger Pack <rogerpack2...@gmail.com> wrote:
> Proposal:
> Change def to return a Method instance [1]

Also http://oldrcrs.rubypal.com/rcr/show/277
in addition to #15 @ http://rcrchive.net/ (except that it doesn't seem
to be working right now).

0 new messages