3 ms·
There are no 'keyword arguments', however Ruby does provide syntax sugar for options hashes. For example, this: my_method(1, 2, three: 3, four: 4) Is the
by charliesome 14y ago
There are no 'keyword arguments', however Ruby does provide syntax sugar for options hashes.
For example, this:
my_method(1, 2, three: 3, four: 4)
Is the same as this:
my_method(1, 2, { three: 3, four: 4 })
Which can be picked up by the method like this:
def my_method(one, two, opts)
three = opts[:three]
four = opts[:four]
puts one, two, three, four
end