Skip to content

Commit

Permalink
Merge pull request #734 from koic/support_except
Browse files Browse the repository at this point in the history
Support `Thor::CoreExt::HashWithIndifferentAccess#except` for Rails 6.0
  • Loading branch information
rafaelfranca authored Feb 11, 2021
2 parents b60e9eb + 99a15e6 commit 011dc48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/thor/core_ext/hash_with_indifferent_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def delete(key)
super(convert_key(key))
end

def except(*keys)
dup.tap do |hash|
keys.each { |key| hash.delete(convert_key(key)) }
end
end

def fetch(key, *args)
super(convert_key(key), *args)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/core_ext/hash_with_indifferent_access_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
expect(@hash.delete(:foo)).to eq("bar")
end

it "supports except" do
unexcepted_hash = @hash.dup
@hash.except("foo")
expect(@hash).to eq(unexcepted_hash)

expect(@hash.except("foo")).to eq("baz" => "bee", "force" => true)
expect(@hash.except("foo", "baz")).to eq("force" => true)
expect(@hash.except(:foo)).to eq("baz" => "bee", "force" => true)
expect(@hash.except(:foo, :baz)).to eq("force" => true)
end

it "supports fetch" do
expect(@hash.fetch("foo")).to eq("bar")
expect(@hash.fetch("foo", nil)).to eq("bar")
Expand Down

0 comments on commit 011dc48

Please sign in to comment.