Skip to content

Commit 011dc48

Browse files
authored
Merge pull request #734 from koic/support_except
Support `Thor::CoreExt::HashWithIndifferentAccess#except` for Rails 6.0
2 parents b60e9eb + 99a15e6 commit 011dc48

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/thor/core_ext/hash_with_indifferent_access.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def delete(key)
2828
super(convert_key(key))
2929
end
3030

31+
def except(*keys)
32+
dup.tap do |hash|
33+
keys.each { |key| hash.delete(convert_key(key)) }
34+
end
35+
end
36+
3137
def fetch(key, *args)
3238
super(convert_key(key), *args)
3339
end

spec/core_ext/hash_with_indifferent_access_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
expect(@hash.delete(:foo)).to eq("bar")
1515
end
1616

17+
it "supports except" do
18+
unexcepted_hash = @hash.dup
19+
@hash.except("foo")
20+
expect(@hash).to eq(unexcepted_hash)
21+
22+
expect(@hash.except("foo")).to eq("baz" => "bee", "force" => true)
23+
expect(@hash.except("foo", "baz")).to eq("force" => true)
24+
expect(@hash.except(:foo)).to eq("baz" => "bee", "force" => true)
25+
expect(@hash.except(:foo, :baz)).to eq("force" => true)
26+
end
27+
1728
it "supports fetch" do
1829
expect(@hash.fetch("foo")).to eq("bar")
1930
expect(@hash.fetch("foo", nil)).to eq("bar")

0 commit comments

Comments
 (0)