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

Discussion in 'Ruby' started by Roger Pack, Dec 31, 2009.

  1. Roger Pack

    Roger Pack Guest

    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/.
     
    Roger Pack, Dec 31, 2009
    #1
    1. Advertising

  2. Roger Pack

    Ryan Davis Guest

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


    are unclear. Constructs should generally do one thing only. In this =
    case, define a method.
     
    Ryan Davis, Dec 31, 2009
    #2
    1. Advertising

  3. Roger Pack

    Phrogz Guest

    Phrogz, Jan 2, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    844
    Jiong Feng
    Nov 19, 2003
  2. Sean Ross
    Replies:
    3
    Views:
    127
    Aredridel
    Dec 25, 2003
  3. Replies:
    7
    Views:
    162
  4. Kyung won Cheon
    Replies:
    1
    Views:
    105
    Pit Capitain
    Aug 18, 2008
  5. Kyung won Cheon
    Replies:
    0
    Views:
    208
    Kyung won Cheon
    Nov 21, 2008
Loading...

Share This Page