4 ms·
It's only two keystrokes if your parameters are single characters. def some_method(with_longer_parameters: with_longer_parameters) do_something(with_long
by mostlysimilar 5y ago
It's only two keystrokes if your parameters are single characters.
def some_method(with_longer_parameters: with_longer_parameters)
do_something(with_longer_parameters)
end
vs
def some_method(with_longer_parameters:)
do_something(with_longer_parameters)
end
- cpb 5y agoIs it to spare keystrokes in method definition, or rather, in method invocation? Your second definition reads that `with_longer_parameters` is a keyword argument with no default. Still, you've illustrated the keystroke savings with your choice of parameter names :-)
- kule 5y agoYeah, should be invocation, there's a nice example on the feature request (https://bugs.ruby-lang.org/issues/14579 https://bugs.ruby-lang.org/issues/14579): def login(username: ENV["USER"], password:) p(username:, password:) end login(password: "xxx") #=> {:username=>"shugo", :password=>"xxx"}