lib/hm.rb
# Preserves only specified pathes from input sequence.
#
# @example
#   order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2}
#   Hm(order).slice(%i[items * title]).to_h
#   # => {:items=>[{:title=>"Beef"}, {:title=>"Potato"}]}
#
# @see #except
# @param pathes [Array] List of pathes (each being singular key, or array of keys, including
#   `:*` wildcard) to look at.
# @return [self]
Preserves only specified pathes from input sequence.
Preserves only specified pathes from input sequence .
def slice(*pathes)
    result = Hm.new({})
    pathes.each do |path|
      Algo.visit(@hash, path) { |_, new_path, val| result.bury(*new_path, val) }
    end
    @hash = result.to_h
    self
  end
def slice ( * pathes ) result = Hm . new ( { } ) pathes . each do | path | Algo . visit ( @hash , path ) { | _ , new_path , val | result . bury ( * new_path , val ) } end @hash = result . to_h self end
Preserves only specified pathes from input sequence.
Preserves only specified pathes from input sequence .
None
self
pathes
List of pathes (each being singular key, or array of keys, including `:*` wildcard) to look at.
List of pathes ( each being singular key or array of keys including ` : * ` wildcard ) to look at .
example
None
see
None