Are you suggesting using the variable named defaults in the rest of the method, rather than the variable named options?
Andrew On Wed, Mar 11, 2009 at 9:43 PM, Torm3nt <[email protected]> wrote: > Unless I'm misunderstanding it, I'm pretty sure it sets defaults with the > new options, without you having to do: defaults = defaults.merge(options) > > > On Wed, Mar 11, 2009 at 9:39 PM, Andrew Grimm <[email protected]>wrote: > >> Wouldn't that modify defaults, not options? >> >> Andrew >> >> >> On Wed, Mar 11, 2009 at 8:46 PM, Torm3nt <[email protected]> wrote: >> >>> Can't you do defaults.merge!(options) to modify the object in place? >>> Kirk >>> >>> >>> On Wed, Mar 11, 2009 at 5:33 PM, Andrew Grimm >>> <[email protected]>wrote: >>> >>>> This is probably personal preference, but I usually use an explaining >>>> variable of defaults and have >>>> >>>> defaults = {:width => 800, :align => :left_justify} >>>> options = defaults.merge(options) >>>> >>>> This doesn't mutate the existing options object but creates a new >>>> object. I'm not sure if this is a bug or feature. >>>> >>>> I use double quotes rather than single, but that's because I use plain >>>> command line ruby rather than rails. >>>> >>>> Andrew >>>> >>>> >>>> On Wed, Mar 11, 2009 at 4:03 PM, David Phillips <[email protected] >>>> > wrote: >>>> >>>>> >>>>> On 11/03/2009, at 11:20 AM, Christopher Robbie wrote: >>>>> >>>>> > c = a || b >>>>> > >>>>> > if 'a' is got something, use it, if 'a' is nil(or false) then use >>>>> 'b'. >>>>> > love it. >>>>> >>>>> c ||= a >>>>> >>>>> c = a, but only if c is nil >>>>> >>>>> def do_something options >>>>> options[:width] ||= 800 >>>>> options[:align] ||= :left_justify >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>> >>> >>> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" 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/rails-oceania?hl=en -~----------~----~----~----~------~----~------~--~---
