Skip to content

Commit

Permalink
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/dig_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Array#dig returns the nested value specified if the sequence includes a key
fails:Array#dig raises a TypeError if any intermediate step does not respond to #dig
10 changes: 0 additions & 10 deletions spec/truffle/tags/core/hash/dig_tags.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
fails:Hash#dig returns [] with one arg
fails:Hash#dig does recurse
fails:Hash#dig raises without args
fails:Hash#dig handles type-mixed deep digging
fails:Hash#dig returns #[] with one arg
fails:Hash#dig raises TypeError if an intermediate element does not respond to #dig
fails:Hash#dig calls #dig on the result of #[] with the remaining arguments
fails:Hash#dig returns the nested value specified by the sequence of keys
fails:Hash#dig returns the nested value specified if the sequence includes an index
fails:Hash#dig returns nil if any intermediate step is nil
fails:Hash#dig raises an ArgumentError if no arguments provided
9 changes: 9 additions & 0 deletions truffle/src/main/ruby/core/hash.rb
Original file line number Diff line number Diff line change
@@ -149,6 +149,15 @@ def default_proc=(prc)
@default_proc = prc
end

def dig(key, *more)
result = self[key]
if result.nil? || more.empty?
result
else
result.dig(*more)
end
end

def fetch(key, default=undefined)
if item = find_item(key)
return item.value

0 comments on commit 8e8d9c1

Please sign in to comment.