I am trying to write a method, that works with three types of arguments, but requires only one of them.
def convert(arg_a: 1, arg_b: 2, arg_c: 'foo') end
Please note, that both: arg_a, and arg_b are the same type (let's say Numeric), so using one mandatory argument, and then making decision based on the input type won't work here.
At this point my code looks like this:
def convert(arg_a: nil, arg_b: nil, arg_c: nil) if arg_b.nil? && arg_c.nil? && arg_a # do something with arg_a elsif arg_a.nil? && arg_c.nil? && arg_b # do something with arg_b elsif arg_a.nil? && arg_b.nil? && arg_c # do something with arg_c else raise ArgumentError end
In my opinion this code smells a little, and can be improved. Any thoughts?