
18 Dec
2022
18 Dec
'22
1:41 a.m.
On December 18, 2022 1:09:51 AM UTC, Henry R via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:
def tt2 (x:123) puts x end
tt2 123 tt2(456) ArgumentError (wrong number of arguments (given 1, expected 0)) tt2(x:456) 456 tt2(:x=>456) 456
what's the trick behind it?
"x" in tt2 is a keyword argument: https://docs.ruby-lang.org/en/3.0/syntax/methods_rdoc.html#label-Keyword+Arg... https://thoughtbot.com/blog/ruby-2-keyword-arguments https://www.bigbinary.com/blog/ruby-2-7-deprecates-conversion-of-keyword-arg...