Created
February 16, 2022 18:23
-
-
Save yaauie/b0729262b12264ba44e9cdebd3e68865 to your computer and use it in GitHub Desktop.
Reproduction demonstrating a difference in behaviour between MRI and JRuby for keyword arg splats of aliased methods, as discovered in Sinatra 2.2.0
This file contains hidden or 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
╭─{ yaauie@limbo:~/src/elastic/ls (✔ 8.0) } | |
╰─● (rbenv shell jruby-9.2.19.0; ruby kwargs-splat.rb) | |
ArgumentError: wrong number of arguments calling `initialize` (given 1, expected 0) | |
new at kwargs-splat.rb:7 | |
<main> at kwargs-splat.rb:17 | |
( rbenv shell jruby-9.2.19.0; ruby kwargs-splat.rb; ) 9.23s user 0.53s system 405% cpu 2.412 total | |
[error: 1] |
This file contains hidden or 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
class Base | |
class << self | |
alias new! new unless method_defined? :new! | |
def new(*args, **kwargs, &bk) | |
instance = new!(*args, **kwargs, &bk) | |
$stderr.puts("intercepted creation of `#{instance.inspect}`") | |
instance | |
end | |
end | |
end | |
class Foo < Base | |
end | |
$stdout.puts Foo.new |
This file contains hidden or 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
╭─{ yaauie@limbo:~/src/elastic/ls (✔ 8.0) } | |
╰─● (rbenv shell 2.7.2; ruby kwargs-splat.rb) | |
intercepted creation of `#<Foo:0x00007fef0a0f8150>` | |
#<Foo:0x00007fef0a0f8150> | |
[success] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment