Feature #4172
Named arguments/parameters support
| Status: | Rejected | Start date: | 12/20/2010 | |
|---|---|---|---|---|
| Priority: | Low | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | - |
Description
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?
History
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 1 year ago
Sorry, I meant: tag(tag_name -> 'div', content -> 'Ruby is getting even more awesome with this feature!')
Updated by matz (Yukihiro Matsumoto) over 1 year ago
Hi, In message "Re: [ruby-core:33774] [Ruby 1.9-Feature#4172][Open] Named arguments/parameters support" on Mon, 20 Dec 2010 08:13:36 +0900, Rodrigo Rosenfeld Rosas <redmine@ruby-lang.org> writes: |Feature #4172: Named arguments/parameters support |http://redmine.ruby-lang.org/issues/show/4172 Ruby 2.0 will have named arguments. The spec is bit different from your proposal though. matz.
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 1 year ago
Great! Is there any place I can see the spec? Thank you and best regards! Rodrigo
Updated by shyouhei (Shyouhei Urabe) about 1 year ago
- Status changed from Open to Assigned
Updated by naruse (Yui NARUSE) 7 months ago
- Project changed from ruby-trunk to 14
- Category deleted (
core) - Target version deleted (
3.0)
Updated by naruse (Yui NARUSE) 7 months ago
- Project changed from 14 to ruby-trunk
Updated by kosaki (Motohiro KOSAKI) 4 months ago
- Status changed from Assigned to Rejected
Current trunk (for 2.0) has a keyword argument feature. Please look at and give us comments.
Thanks.
Updated by rosenfeld (Rodrigo Rosenfeld Rosas) 4 months ago
I wouldn't say this was rejected, but implemented/accepted instead ;)