Skip to content

Commit

Permalink
✅ Fix ruby 2.7 compatibility
Browse files Browse the repository at this point in the history
ruby 2.7 didn't have:
* Hash#except.
* pattern matching statements: "foo => a | b | c"
  • Loading branch information
nevans committed Jun 22, 2024
1 parent 471c307 commit e2b341a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ def with(**attrs)
def load_defaults(version)
[Numeric, Symbol, String].any? { _1 === version } or
raise ArgumentError, "expected number or symbol, got %p" % [version]
update(**Config[version].to_h.except(*DEFAULT_TO_INHERIT))
config = Config[version]
defaults = config.to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
update(**defaults)
end

# :call-seq: to_h -> hash
Expand All @@ -300,7 +302,7 @@ def to_h; data.members.to_h { [_1, send(_1)] } end
@global = default.new

version_defaults[0.4] = Config[
default.to_h.except(*DEFAULT_TO_INHERIT)
default.to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
]

version_defaults[0] = Config[0.4].dup.update(
Expand Down
2 changes: 1 addition & 1 deletion test/net/imap/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ConfigTest < Test::Unit::TestCase

test ".version_defaults are all frozen, and inherit debug from global" do
Config.version_defaults.each do |name, config|
name => 0 | Float | Symbol
assert [0, Float, Symbol].any? { _1 === name }
assert_kind_of Config, config
assert config.frozen?, "#{name} isn't frozen"
assert config.inherited?(:debug), "#{name} doesn't inherit debug"
Expand Down

0 comments on commit e2b341a

Please sign in to comment.