module UniverseCompiler::Utils::DeepTraverse

Public Instance Methods

deep_map(structure) { |structure| ... } click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 17
def deep_map(structure, &block)
  case structure
  when Hash
    deep_map_hash structure, &block
  when Array
    deep_map_array structure, &block
  else
    yield structure
  end
end
deep_traverse(structure) { |structure| ... } click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 6
def deep_traverse(structure, &block)
  case structure
  when Hash
    deep_traverse_hash structure, &block
  when Array
    deep_traverse_array structure, &block
  else
    yield structure
  end
end

Private Instance Methods

deep_map_array(array, res = [], &block) click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 51
def deep_map_array(array, res = [], &block)
  array.each.with_index do |v, idx|
    res[idx] = deep_map v, &block
  end
  res
end
deep_map_hash(hash, res = {}, &block) click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 43
def deep_map_hash(hash, res = {}, &block)
  hash.each do |k, v|
    k = deep_map k, &block
    res[k] = deep_map v, &block
  end
  res
end
deep_traverse_array(array, &block) click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 37
def deep_traverse_array(array, &block)
  array.each.with_index do |v, idx|
    deep_traverse v, &block
  end
end
deep_traverse_hash(hash, &block) click to toggle source
# File lib/universe_compiler/utils/deep_traverse.rb, line 30
def deep_traverse_hash(hash, &block)
  hash.each do |k, v|
    deep_traverse k, &block
    deep_traverse v, &block
  end
end