Created
November 5, 2021 19:08
-
-
Save jaredcwhite/fd6f90436a550e6095849e7c99ebec03 to your computer and use it in GitHub Desktop.
Ruby 2.7.2 vs. 3.0.2 discrepancy
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
# This file runs fine in Ruby 2.7.2 and errors out in Ruby 3.0.2 with: | |
# testkwargs.rb:15:in `method_missing': no implicit conversion of Foo into Hash (TypeError) | |
# from testkwargs.rb:31:in `<main>' | |
class Helpers | |
end | |
class Foo | |
def wee(a=1, b:2) | |
puts a | |
puts b | |
end | |
end | |
class Bar | |
attr_accessor :helpers | |
def method_missing(method, *args, **kwargs, &block) | |
if helpers.respond_to?(method.to_sym) | |
helpers.send method.to_sym, *args, **kwargs, &block | |
else | |
super | |
end | |
end | |
end | |
foo = Foo.new | |
meth = foo.method(:wee) | |
m = Module.new | |
m.define_method :wee, &meth | |
Helpers.include(m) | |
bar = Bar.new | |
bar.helpers = Helpers.new | |
bar.wee |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment