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

R

Roger Pack

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
 
R

Ryan Davis

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
=20
end.do_something_to_it

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top