I want to avoid doing this:
if a
some_method(a, b)
else
some_method(b)
end
some_method is a function that accepts two parameters, first is a namespace, if not provided then it just accepts the method (b).
Notes:
- I can’t send ‘a’ with an empty string or nil.
- I can’t modify some_method.
Is there a way to do this in one single line?
It seems you have a method which allows a variable number of arguments. You could do it like this:
What this does: the compact removes nils from a list. Then the * ( splat operator ), “expands” the array elements into the proper positions.