Merge pull request #4295 from wataash/struct-dig

Move `Object#dig` to `Struct#dig`
This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-02-24 18:13:56 +09:00
committed by GitHub
+15 -16
View File
@@ -81,23 +81,22 @@ if Object.const_defined?(:Struct)
# 15.2.18.4.11(x)
#
alias to_s inspect
end
##
# call-seq:
# hsh.dig(key,...) -> object
#
# Extracts the nested value specified by the sequence of <i>key</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def dig(idx,*args)
n = self[idx]
if args.size > 0
n&.dig(*args)
else
n
##
# call-seq:
# hsh.dig(key,...) -> object
#
# Extracts the nested value specified by the sequence of <i>key</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def dig(idx,*args)
n = self[idx]
if args.size > 0
n&.dig(*args)
else
n
end
end
end
end