Skip to content

Commit

Permalink
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 0 additions & 7 deletions spec/truffle/tags/core/array/dig_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
fails:Array#dig returns #at with one arg
fails:Array#dig recurses array elements
fails:Array#dig raises without any args
fails:Array#dig calls #dig on the result of #at with the remaining arguments
fails:Array#dig raises a TypeError for a non-numeric index
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
fails:Array#dig raises an ArgumentError if no arguments provided
fails:Array#dig returns nil if any intermediate step is nil
9 changes: 9 additions & 0 deletions truffle/src/main/ruby/core/array.rb
Original file line number Diff line number Diff line change
@@ -315,6 +315,15 @@ def cycle(n=nil)
nil
end

def dig(idx, *more)
result = self.at(idx)
if result.nil? || more.empty?
result
else
result.dig(*more)
end
end

def each_index
return to_enum(:each_index) { size } unless block_given?

0 comments on commit 4e6078d

Please sign in to comment.