Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created February 16, 2022 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/b0729262b12264ba44e9cdebd3e68865 to your computer and use it in GitHub Desktop.
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
╭─{ 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]
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
╭─{ 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