You cannot use this syntax for this in ruby. I would recommend hash syntax for this.
def foo(args={}) args[:fruit] ||= 'apple' args[:cut] ||= 'sliced' args[:topping] ||= 'ice cream'
You can also do this with positional arguments:
def foo(fruit=nil,cut=nil,topping=nil) fruit ||= 'apple' cut ||= 'sliced' topping ||= 'ice cream'
Keep in mind that both of these methods prevent the passing of actual nil arguments to functions (whenever you want sometimes)
rampion
source share