I have method to which I want to pass an optional argument. By default I want to set that argument as nil. Here is the way I am doing it:
def my_function(arg1, arg2: nil)
# Do something
end
I call the function as my_function(2, 5)
. I am getting an error which says:
"wrong number of arguments (given 2, expected 1)"
Am I doing something wrong here? I wish to pass a value for arg2 during some calls and want it to be nil otherwise. So when I don't pass a value for arg2, my function call looks like my_function(2)
.