I would like to create a function that has optional arguments with default values
def my_function(a = nil, b=nil, c=500)
end
and call the
So you're trying to implement keyword arguments? This is supposed to be a new feature in Ruby 2.0, but you can try to mimic it in 1.9.x with a hash of arguments instead. Here's a post that discusses how you can accomplish that, which gives the following code sample:
def foo(options = {})
options = {bar: 'bar'}.merge(options)
puts "#{options[:bar]} #{options[:buz]}"
end
foo(buz: 'buz') # => 'bar buz'