Created
June 1, 2022 21:00
-
-
Save rattrayalex/2abdf9a722801b0b3ca04a824a5577e0 to your computer and use it in GitHub Desktop.
Fiddling with kwargs in Ruby 3 at https://try.ruby-lang.org/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts RUBY_VERSION | |
def foo(params={}, x: nil, **kwargs) | |
puts({params: params, x: x, kwargs: kwargs}) | |
end | |
foo(a: 1) | |
foo(a: 1, x: 2) | |
foo(x: 1) | |
foo({a: 1}) | |
foo({a: 1}, x: 1) | |
foo(a: 1, x: 1, b: 2) | |
foo({a: 1}, x: 1, b: 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3.1.0 | |
{"params"=>{}, "x"=>nil, "kwargs"=>{"a"=>1}} | |
{"params"=>{}, "x"=>2, "kwargs"=>{"a"=>1}} | |
{"params"=>{}, "x"=>1, "kwargs"=>{}} | |
{"params"=>{}, "x"=>nil, "kwargs"=>{"a"=>1}} | |
{"params"=>{"a"=>1}, "x"=>1, "kwargs"=>{}} | |
{"params"=>{}, "x"=>1, "kwargs"=>{"a"=>1, "b"=>2}} | |
{"params"=>{"a"=>1}, "x"=>1, "kwargs"=>{"b"=>2}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment