Move `Object#dig` to `Struct#dig`

This method seems to be mistakenly put into `Object` instead of `Struct`
since it's in `struct.rb` and daf83946 says:

  add #dig to Array,Hash and Struct
parent f5cfb770
...@@ -81,23 +81,22 @@ if Object.const_defined?(:Struct) ...@@ -81,23 +81,22 @@ if Object.const_defined?(:Struct)
# 15.2.18.4.11(x) # 15.2.18.4.11(x)
# #
alias to_s inspect alias to_s inspect
end
## ##
# call-seq: # call-seq:
# hsh.dig(key,...) -> object # hsh.dig(key,...) -> object
# #
# Extracts the nested value specified by the sequence of <i>key</i> # Extracts the nested value specified by the sequence of <i>key</i>
# objects by calling +dig+ at each step, returning +nil+ if any # objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+. # intermediate step is +nil+.
# #
def dig(idx,*args) def dig(idx,*args)
n = self[idx] n = self[idx]
if args.size > 0 if args.size > 0
n&.dig(*args) n&.dig(*args)
else else
n n
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment