3 ms·
i don't know ruby, so forgive the dumb question, but doesn't that mean that a single syntax has two different semantics? what if you want to pass a hash to a m
by andrewcooke 14y ago
i don't know ruby, so forgive the dumb question, but doesn't that mean that a single syntax has two different semantics? what if you want to pass a hash to a method as the last parameter? what decides whether it is treated as a hash or keywords?
- charliesome 14y agoThere 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