delegate or return something specific with the built-in delegate
Posted by Chad Humphries 3 months ago / Source: http://dev.rubyonrails.org/ticket/4134
# You can get the short-circuit behavior you're looking for with the following 
# construct:
delegate :foo, :wibble, :to => '(bar or return nil)'

# Some people will probably find sticking an expression in the :to a bit ugly 
# but it does allow you greater freedom than just "always return nil if :to 
# evaluates to nil":
delegate :foo, :wibble, :to => '(bar or return "bar not there")'

# You could probably make a (strong) argument that it would be clearer to write 
# custom accessors - but personally I like the way delegate() works right now.
Language Ruby / Tagged with rails