File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -207,13 +207,20 @@ describe "NamedTuple" do
207
207
i.should eq(2 )
208
208
end
209
209
210
- it " does has_key?" do
210
+ it " does has_key? with symbol " do
211
211
tup = {a: 1 , b: 'a' }
212
212
tup.has_key?(:a ).should be_true
213
213
tup.has_key?(:b ).should be_true
214
214
tup.has_key?(:c ).should be_false
215
215
end
216
216
217
+ it " does has_key? with string" do
218
+ tup = {a: 1 , b: 'a' }
219
+ tup.has_key?(" a" ).should be_true
220
+ tup.has_key?(" b" ).should be_true
221
+ tup.has_key?(" c" ).should be_false
222
+ end
223
+
217
224
it " does empty" do
218
225
{a: 1 }.empty?.should be_false
219
226
end
Original file line number Diff line number Diff line change @@ -219,6 +219,14 @@ struct NamedTuple
219
219
false
220
220
end
221
221
222
+ # ditto
223
+ def has_key ?(key : String ) : Bool
224
+ {% for key in T % }
225
+ return true if {{key.stringify}} == key
226
+ {% end % }
227
+ false
228
+ end
229
+
222
230
# Appends a string representation of this named tuple to the given `IO`.
223
231
#
224
232
# ```
You can’t perform that action at this time.
0 commit comments