Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add :writer attribute to delegate method

#5582

I've created a patch to add a :writer attribute to the delegate method. The :writer method, when set, constructs a delegate method to the writer of the method passed in. An example:

delegate :name, :to => :client, :writer => true #=> results in #name and #name= methods being added.

The patch is at http://github.com/nathankleyn/rails/commit/373cf623b5833957edb6e7aa..., diff is attached.

p.s. Never done this before, and only really a newbie to Ruby/Rails, so please excuse any crap coding... =]

Reported by Nathan Kleyn · September 8th, 2010 @ 04:30 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Nathan Kleyn
    Nathan Kleyn
    • Tag set to delegate method, activesupport

    The diff didn't attach last round, here it is.

    September 8th, 2010 @ 04:34 PM

  2. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    Hi Nathan,

    Nice patch, but I don't think this would add anything that's really useful or missing right now. I'm curious about what the rest thinks, though. :)

    -1

    September 8th, 2010 @ 05:25 PM

  3. David Trasbo
    David Trasbo

    A big -1 from here too, sorry.

    Doing:

    delegate :name, :name=, :to => :client
    

    is not only shorter, it's also more readable and concise.

    September 9th, 2010 @ 07:58 AM

  4. Nathan Kleyn
    Nathan Kleyn

    I did it more for situations where one would like to delegate a handful of methods, but not have to explicitly write the writer methods out:

    delegate :name, :phone_number, :street, :city, :to => :client, :writer => true
    

    It was something that came in handy when for a large and complex API building project; we needed to keep data off a particular model acting as a tree, so we could version each node at their smaller size. It's a rather niche feature though, so I completely understand the -1's. One learns by trying though, right? =]

    For all intents and purposes, :writer is only helpful when delegating multiple methods with writers.

    September 9th, 2010 @ 09:08 AM

  5. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from new to wontfix
    • Importance changed from to Low

    I think I understand your point, but I still think this would be better as a plugin. I'm marking this one as wontfix, keep up the great work though! :)

    October 10th, 2010 @ 09:09 AM

  6. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:10 PM