0

when there are 2 default arguments defined for both parameters of method, is there a way to call this method and pass it argumen

when there are 2 default arguments defined for both parameters of method, is there a way to call this method and pass it argument for the second parameter only? e.g. def myfunc (x=1, y=2) { x+y } how to call myfunc and pass it only y?

5th Mar 2017, 11:49 PM
Artem
Artem - avatar
2 Respostas
+ 11
AFAIK, you can pass either both x and y, or only x, but not only y, due to their respective positions in the formal parameter list.
5th Mar 2017, 11:58 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
it's actually isn't possible for ruby version < 2. here are the details: http://stackoverflow.com/questions/16322706/optional-arguments-with-default-value-in-ruby
6th Mar 2017, 12:08 AM
Artem
Artem - avatar