This project is archived and is in readonly mode.
Add :writer attribute to delegate method
Reported by Nathan Kleyn | September 8th, 2010 @ 04:30 PM
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... =]
Comments and changes to this ticket
-
Nathan Kleyn September 8th, 2010 @ 04:34 PM
- Tag set to delegate method, activesupport
The diff didn't attach last round, here it is.
-
Jeff Kreeftmeijer September 8th, 2010 @ 05:25 PM
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
-
David Trasbo September 9th, 2010 @ 07:58 AM
A big -1 from here too, sorry.
Doing:
delegate :name, :name=, :to => :client
is not only shorter, it's also more readable and concise.
-
Nathan Kleyn September 9th, 2010 @ 09:08 AM
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.
-
Jeff Kreeftmeijer October 10th, 2010 @ 09:09 AM
- 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! :)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>