E
eliben
Hello all,
What is the current idiomatic approach to pass named arguments to a
method in Ruby ?
In Perl, I can do:
sub method
{
# first the defaults are specified, then @_ is appended and overrides
# the defaults, using Perl's array-folding-into-hash feature
#
my %args = ("size" => 45,
"length" => 12,
@_);
my $the_size = $args{"size"};
}
# now, a call: 44 will override the default size 45, but length will
remain 12
#
method("size" => 44);
I'm sure Ruby has a nearly similar approach to achieve this, I just not
skilled enough (yet) to know how. Please advise.
Thanks in advance
Eli
What is the current idiomatic approach to pass named arguments to a
method in Ruby ?
In Perl, I can do:
sub method
{
# first the defaults are specified, then @_ is appended and overrides
# the defaults, using Perl's array-folding-into-hash feature
#
my %args = ("size" => 45,
"length" => 12,
@_);
my $the_size = $args{"size"};
}
# now, a call: 44 will override the default size 45, but length will
remain 12
#
method("size" => 44);
I'm sure Ruby has a nearly similar approach to achieve this, I just not
skilled enough (yet) to know how. Please advise.
Thanks in advance
Eli