I have a function like:
def set_blah
self.prop1 = .... if new_record?
end
I want to be able to force an update even if it isn’t a new record in some cases, can I just add an optional parameter here so all other calls that I have already won’t break?
i.e.
def set_blah ( force )
self.prop1 = ... if new_record? || force
end
Yes, default parameters are simply specified in the method signature:
You might try using options to make your calling sequence more readable:
By specifying it this explicitly, your calling sequence is something like:
or
which seems to make it clearer at the call point what @set_blah@ does. Also, your rdoc will show the method’s default arguments so it’s kind of self-documenting.