Class: DiscoveryV1::Validation::TraverseObjectTree
- Inherits:
-
Object
- Object
- DiscoveryV1::Validation::TraverseObjectTree
- Defined in:
- lib/discovery_v1/validation/traverse_object_tree.rb
Overview
Visit all objects in arbitrarily nested object tree of hashes and/or arrays
Class Method Summary collapse
-
.call(object:, visitor:, path: [])
Visit all objects in arbitrarily nested object tree of hashes and/or arrays.
Class Method Details
.call(object:, visitor:, path: [])
This method returns an undefined value.
Visit all objects in arbitrarily nested object tree of hashes and/or arrays
For each object, the visitor is called with the path to the object and the object itself.
70 71 72 73 74 75 76 77 |
# File 'lib/discovery_v1/validation/traverse_object_tree.rb', line 70 def self.call(object:, visitor:, path: []) visitor&.call(path:, object:) if object.is_a? Hash object.each { |k, obj| call(path: (path + [k]), object: obj, visitor:) } elsif object.is_a? Array object.each_with_index { |obj, k| call(path: (path + [k]), object: obj, visitor:) } end end |