I have a method like this:
def foo(fruit='apple', cut='sliced', topping='ice cream') # some logic here end
How can I call it where I only override the topping parameter but use the default values for the others, something like this
foo('','','hot fudge')
Of course this does not work as intended, but I want to only provide a value for the third optional parameter, and have the first two stick with their default values. I know how to do this with a hash, but is their a shortcut way to do it, using the above syntax?
You can’t use this syntax to do this in ruby. I would recommend the hash syntax for this.
You could also do this using positional arguments:
Bear in mind that both of these techniques prevent you from passing actual
nilarguments to functions (when you might want to sometimes)