For the example I showed, you are absolutely right. The reason I don't do it that way is that I want to treat false and nil differently -- false meaning the local should be set to false, and nil and undefined mean use the default value. My example didn't really show that case...that it would be something more like:
- bar = true unless defined?(bar) && !bar.nil? This way, bar will be set to a default value of true if the caller of the partial does not set bar, or sets it to nil, but if they explicitly set it to false, it will stay false. I use that style shown above in all cases to be consistent, but I suppose it may be easier to read if I only used it specifically when I have that boolean case. Also, I imagine some people would find it awkward to treat nil/false the differently the way I do. So yeah, I agree -- do it the way Adam suggested. On Jun 18, 6:48 am, Adam Strzelecki <[email protected]> wrote: > > - foo = nil unless defined?(foo) > > - bar = 42 unless defined?(bar) && bar > > Correct me if I'm wrong but: > - foo ||= nil > - bar ||= 42 > > May be quicker and shorter way to force default values for undefined > or nil or false values. > > Cheers, > -- > Adam --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Haml" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/haml?hl=en -~----------~----~----~----~------~----~------~--~---
