Module: RecursiveOpenStruct::Dig
- Included in:
- RecursiveOpenStruct
- Defined in:
- lib/recursive_open_struct/dig.rb
Instance Method Summary collapse
-
#dig(name, *names) ⇒ Object
Replaces OpenStruct#dig to properly support treating nested values as RecursiveOpenStructs instead of returning the nested Hashes.
Instance Method Details
#dig(name, *names) ⇒ Object
Replaces OpenStruct#dig to properly support treating nested values as RecursiveOpenStructs instead of returning the nested Hashes.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/recursive_open_struct/dig.rb', line 6 def dig(name, *names) begin name = name.to_sym rescue NoMethodError raise TypeError, "#{name} is not a symbol nor a string" end name_val = self[name] if names.length > 0 && name_val.respond_to?(:dig) name_val.dig(*names) else name_val end end |