Ruby2: keyword argument

D

David Garamond

Will Ruby2 support required keyword argument? AFAIR, Python doesn't:

def foo(a, b=2):
...

foo(a=1) # ok
foo(a=1, b=2) # ok

and Perl6 will:

sub foo(+$a is required, +$b is required) {
...
}

# note: i'm not sure about the exact P6 syntax for calling
foo(a: 1); # error!
foo(a: 1, b: 2) # ok

This is being discussed at perl6-language list right now. I also believe
with the poster that basically said required keyword argument is
essential for a "proper" keyword-based API.

Also, implementation-wise, will the introduction of keyword arguments in
Ruby2 bring a performance hit to all method calls, including positional
arguments? (I.e., will normal/positional argument calls in Ruby2 be
slower than Ruby1?)
 
G

gabriele renzi

il Wed, 21 Apr 2004 00:34:14 +0900, David Garamond
Will Ruby2 support required keyword argument? AFAIR, Python doesn't:

def foo(a, b=2):
...

foo(a=1) # ok
foo(a=1, b=2) # ok

python does and so will ruby2.
See matz slide from latest rubyconf for other info.
basically, you'll write
method(name: value)
where name:value is the new hash literal for :name => value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top