From: Rodrigo Rosenfeld Rosas Date: 2010-12-20T08:13:36+09:00 Subject: [ruby-core:33774] [Ruby 1.9-Feature#4172][Open] Named arguments/parameters support Feature #4172: Named arguments/parameters support http://redmine.ruby-lang.org/issues/show/4172 Author: Rodrigo Rosenfeld Rosas Status: Open, Priority: Low Assigned to: Yukihiro Matsumoto, Category: core, Target version: 2.0 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? ---------------------------------------- http://redmine.ruby-lang.org