Created
August 7, 2024 07:49
-
-
Save mostlyobvious/3fc31fdd8af1319745d29426408a8a90 to your computer and use it in GitHub Desktop.
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
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
ruby "2.7.8" # keyword-hash deprecation warnings | |
gem "concurrent-ruby", "1.3.3" | |
end | |
Warning[:deprecated] = true # must be enabled | |
Warning.extend( | |
Module.new do | |
def warn(msg) # overridden to log Ruby warnings same as Rails warnings | |
puts msg | |
Thread.pass # simulates ActiveSupport::Dependencies.warn as we used in production to log instances of deprecations | |
end | |
end | |
) | |
class Kaka | |
def provide(input:) | |
input.fetch("claim_id") | |
end | |
end | |
class Dudu | |
def provide(input:) | |
_claim_id = input.fetch("claim_id") # assignment to make it different frm Kaka#provide | |
end | |
end | |
pending_promises = | |
[Kaka.new, Dudu.new].map do |provider| | |
Concurrent::Promises.future do | |
provider.provide({ input: { "claim_id" => "LPC009-639-035" } }) # pass hash to keywords, incorrectly but still allowed in 2.7 | |
end | |
end | |
sleep(1) # wait a moment to resolve futures | |
pp(pending_promises) | |
# ➜ ruby-2-7-keywords-futures git:(repro) ✗ ruby repro.rb | |
# repro.rb:36: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call | |
# repro.rb:36: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call | |
# repro.rb:22: warning: The called method `provide' is defined here | |
# repro.rb:28: warning: The called method `provide' is defined here | |
# [#<Concurrent::Promises::Future:0x000000012d0ba148 rejected with #<NoMethodError: undefined method `fetch' for #<Kaka:0x000000012d0bb138>>>, | |
# #<Concurrent::Promises::Future:0x000000012d0b8578 fulfilled with "LPC009-639-035">] | |
# | |
# ➜ ruby-2-7-keywords-futures git:(repro) ✗ ruby repro.rb | |
# repro.rb:36: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call | |
# repro.rb:36: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call | |
# repro.rb:28: warning: The called method `provide' is defined here | |
# repro.rb:22: warning: The called method `provide' is defined here | |
# [#<Concurrent::Promises::Future:0x000000012c846818 fulfilled with "LPC009-639-035">, | |
# #<Concurrent::Promises::Future:0x000000012c844a90 rejected with #<NoMethodError: undefined method `fetch' for 0:Integer>>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment