Skip to content

Commit 5279d59

Browse files
committed
Merge pull request #478 from kiyohara/options_symbol_key_exist_check
Add key? method for improving ::Hash compatibility
2 parents 7611ef2 + 0a7a7aa commit 5279d59

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/thor/core_ext/hash_with_indifferent_access.rb

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

31+
def key?(key)
32+
super(convert_key(key))
33+
end
34+
3135
def values_at(*indices)
3236
indices.map { |key| self[convert_key(key)] }
3337
end

spec/core_ext/hash_with_indifferent_access_spec.rb

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

17+
it "has key checkable by either strings or symbols" do
18+
expect(@hash.key?("foo")).to be true
19+
expect(@hash.key?(:foo)).to be true
20+
21+
expect(@hash.key?("nothing")).to be false
22+
expect(@hash.key?(:nothing)).to be false
23+
end
24+
1725
it "handles magic boolean predicates" do
1826
expect(@hash.force?).to be true
1927
expect(@hash.foo?).to be true

0 commit comments

Comments
 (0)