Feature #4172
closedNamed arguments/parameters support
Description
=begin
It is usual in the Ruby community to use the idiom
def method(options={})
param1, param2 = options.values_at(:param1, :param2) # or {param1: 'default1', param2: 2}.collect{|k, v| options[k] || v }
...
end
instead of
def method(param1, param2)
...
end
Perl 6 supports named arguments (or parameters) out-of-the-box. Suppose the following method (not valid Ruby actually):
def tag(tag_name, :content(''), :attributes({}), :closing_tag(true))
...
end
It would be great if this could be called as
hr = tag('hr', closing_tag -> false, attributes -> {style: 'color: blue'})
It think it should be even possible to call it like
tag(tag_name: 'div', content: 'Ruby is getting even more awesome with this feature!')
I think it is much more legible than
tag('hr', '', {}, false)
or than using an 'options' hash parameter.
Is there any reasons why Ruby doesn't support named parameters as part of the syntax?
=end