This project is archived and is in readonly mode.
:allow_nil option for delegate
-
Daniel Schierbeck
+1: This seems like a good addition to
delegate, and I like the simplicity of the implementation. -
David Röthlisberger
- Useful, and the patch is very simple.
If anything, I'd change the rdoc to say "If the object to which you delegate...".
-
David Röthlisberger
(Um, that "1." in the comment above was supposed to be a "+1").
-
Josh Susser
-1
I dislike silently hiding errors like that. Seems like just asking for trouble.
-
David Röthlisberger
How is it hiding the error any more than:
def contact_name; contact && contact.name; endIt's intended as a shortcut for the case where not having a contact isn't an error. Remember you have to specify :allow_nil, this isn't going to be default behaviour.
-
porras
I updated the patch, which no longer applied after the :prefix option was added.
@Josh, as Dave explained, this option is intended only for the cases where this is not an error but a legitimate situation, just to avoid that verbose and ugly definition.
-
Daniel Schierbeck
I'd like some more attention brought on this ticket (i.e. BUMP), as I've recently found use cases for it abound.
I currently have the following simplified setup:
# A resident may or may not have a current residentship -- he # could be a former resident. class Resident < ActiveRecord::Base has_many :residentships delegate :room_number, :room, :to => :residentship def residentship residentships.only_current.first end end class Residentship < ActiveRecord::Base belongs_to :resident validates_presence_of :room_number, :moved_out_at named_scope :only_current, ... composed_of :room, :mapping => %w(room_number number) end class Room # value class, as there's a finite set of rooms def residentship Residentship.only_current.find_by_room_number(@number) end delegate :resident, :to => :residentships endI'd like
Room#resident,Resident#roomandResident#room_number(as well as several more in my real app) to work properly for former residents, i.e. just return nil -- but with the current implementation ofdelegate, they raise an exception instead. Adding an:allow_niloption todelegatewould greatly reduce the number of extra methods i need to have. -
Repository
- State changed from new to resolved
(from [e8de7a67a5ef063164da022845a7cae1753da80e]) Add :allow_nil option to delegate [#1127 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
yoyogo
oh my!! i love you so much!!
Thank you so much.
Hermes Bags
http://www.louisvuittonparty.com/
Hermes Bags -
slina
iPad 2 Video Converter is perfectly compatible with iPad 2
iPad 2 Video Converter Mac is your best choice to convert videos to iPad 2 on Mac OS X.
DVD to iPad 2 is specially designed for Apple users.
DVD to iPad 2 Mac is a wonderful gift for Mac and iPad users
Play 1080P Blu-ray movies with Blu-ray to iPad 2 Converter
Blu-ray to iPad 2 Mac is definitely your best choice to convert Blu-ray DVD to iPad 2 for playback with with its large and high-resolution screen.

Blu-ray to Nintendo 3DS Converter can easily rip/convert Blu-ray DVD, even protected DVDs and encrypted AACS/ BD+ Blu-ray movies to Nintendo 3DS easily and quickly.
DVD to Nintendo 3DS, actally an all-in-one Blu-ray DVD Converter, enables users to convert Blu-ray (.m2ts) ) or DVD movies (.vob) or ISO image files or IFO to Nintendo 3DS/NDSL/ DS, iPhone 4, iPad 2, Motorola Xoom, Android Phones, iPod Touch, Xbox 360, PSP, PS3, Motorola Droid, Nexus One, HTC EVO 4G, etc for entertainment freely.
