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?
2 odpowiedzi
+ 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.
+ 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