diff options
Diffstat (limited to 'mrbgems/mruby-hash-ext/mrblib')
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 2727e1f65..db4db42e8 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -365,4 +365,21 @@ class Hash key?(key) and self[key] == val } 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 + end + end end |
