Skip to content

Commit

Permalink
Prevent overwriting Hash#except method present in Ruby 3+
Browse files Browse the repository at this point in the history
Ruby 3+ introduced `Hash#except` method natively [1], so we can skip
I18n's custom implementation here if the method is already defined.
This follows the same Rails convention [2].

Note: This seems to be causing a `stack level too deep (SystemStackError)`
with a specific set of Gemfiles under Ruby 3, reported to `SimpleForm`
originally [3].  I haven't been able to fully narrow it down after some
initial investigation, nor reproduce it without the given set of gems in
the Gemfile reported, but it seems there's some interactions between
those gems, and combined with the fact that Ancestry loads I18n early on
to setup the load path [4], is possibly causing calls to `Hash#except`
to hang or raise with the `stack level too deep` error, and after
skipping the method re-declaration here it's not reproducible anymore.

[1] https://bugs.ruby-lang.org/issues/15822
[2] https://github.com/rails/rails/blob/5f3ff60084ab5d5921ca3499814e4697f8350ee7/activesupport/lib/active_support/core_ext/hash/except.rb#L12-L14
[3] heartcombo/simple_form#1724
    steps to reproduce issue: heartcombo/simple_form#1724 (comment)
[4] https://github.com/stefankroes/ancestry/blob/71fe7042791f5943b5370240e4c6068dce73233d/lib/ancestry.rb#L9-L10
  • Loading branch information
carlosantoniodasilva committed Feb 6, 2021
1 parent bb7b689 commit cead3e5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/core_ext/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module HashRefinements
using I18n::HashRefinements
def except(*keys)
dup.except!(*keys)
end
end unless method_defined?(:except)

def except!(*keys)
keys.each { |key| delete(key) }
Expand Down

0 comments on commit cead3e5

Please sign in to comment.