Project

General

Profile

Actions

Feature #4172

closed

Named arguments/parameters support

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 13 years ago. Updated about 12 years ago.

Status:
Rejected
Target version:
-
[ruby-core:33774]

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

Actions #1

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 13 years ago

=begin
Sorry, I meant:

tag(tag_name -> 'div', content -> 'Ruby is getting even more awesome with this feature!')
=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 13 years ago

=begin
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 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.

=end

Actions #3

Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 13 years ago

=begin
Great! Is there any place I can see the spec?

Thank you and best regards!

Rodrigo
=end

Actions #4

Updated by shyouhei (Shyouhei Urabe) about 13 years ago

  • Status changed from Open to Assigned
Actions #5

Updated by naruse (Yui NARUSE) over 12 years ago

  • Project changed from Ruby master to 14
  • Category deleted (core)
  • Target version deleted (3.0)
Actions #6

Updated by naruse (Yui NARUSE) over 12 years ago

  • Project changed from 14 to Ruby master

Updated by kosaki (Motohiro KOSAKI) about 12 years 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) about 12 years ago

I wouldn't say this was rejected, but implemented/accepted instead ;)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0