I suggest the following, as it makes it clear that you have a default value for the assignment if the caller did not specify many_items in the call:
def function(argument = nil) variable = argument || 20 ... end
However, since you indicated that the assignment is only performed if the value is not nil , you need to check the nil value, otherwise you will skip the assignment if the value was false . If you really need this case, then the solution is longer:
def function(argument = nil) variable = argument.nil? ? 20 : argument ... end
source share