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

**URL:** <https://www.ruby-forum.com/t/rcr-def-method-end-return-a-method-object/180923>\
**Category:** Ruby\
**Created:** [December 31, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/rcr-def-method-end-return-a-method-object/180923 "2009-12-31T18:52:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [December 31, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/rcr-def-method-end-return-a-method-object/180923/1 "2009-12-31T18:52:17Z")

</div>

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/](http://rcrchive.net/) the idea isn’t new

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [December 31, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/rcr-def-method-end-return-a-method-object/180923/2 "2009-12-31T20:40:07Z")

</div>

On Dec 31, 2009, at 09:52 , Roger P. 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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [January 2, 2010, 4:29am UTC](https://www.ruby-forum.com/t/rcr-def-method-end-return-a-method-object/180923/3 "2010-01-02T04:29:43Z")

</div>

On Dec 31 2009, 10:52 am, Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

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