lib/hm.rb
# Performs specified transformations on keys of input sequence, optionally limited only by specified
# pathes.
#
# Note that when `pathes` parameter is passed, only keys directly matching the pathes are processed,
# not entire sub-collection under this path.
#
# @example
#   order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2}
#   Hm(order).transform_keys(&:to_s).to_h
#   # => {"items"=>[{"title"=>"Beef", "price"=>18.0}, {"title"=>"Potato", "price"=>8.2}], "total"=>26.2}
#   Hm(order)
#     .transform_keys(&:to_s)
#     .transform_keys(['items', :*, :*], &:capitalize)
#     .transform_keys(:*, &:upcase).to_h
#   # => {"ITEMS"=>[{"Title"=>"Beef", "Price"=>18.0}, {"Title"=>"Potato", "Price"=>8.2}], "TOTAL"=>26.2}
#
# @see #transform_values
# @see #transform
# @param pathes [Array] List of pathes (each being singular key, or array of keys, including
#   `:*` wildcard) to look at.
# @yieldparam key [Array] Current key to process.
# @return [self]
Performs specified transformations on keys of input sequence, optionally limited only by specified
pathes.

Note that when `pathes` parameter is passed, only keys directly matching the pathes are processed,
not entire sub-collection under this path.
Performs specified transformations on keys of input sequence optionally limited only by specified pathes . Note that when ` pathes ` parameter is passed only keys directly matching the pathes are processed not entire sub - collection under this path .
def transform_keys(*pathes)
    if pathes.empty?
      Algo.visit_all(@hash) do |at, path, val|
        if at.is_a?(Hash)
          at.delete(path.last)
          at[yield(path.last)] = val
        end
      end
    else
      pathes.each do |path|
        Algo.visit(@hash, path) do |at, pth, val|
          Algo.delete(at, pth.last)
          at[yield(pth.last)] = val
        end
      end
    end
    self
  end
def transform_keys ( * pathes ) if pathes . empty? Algo . visit_all ( @hash ) do | at , path , val | if at . is_a? ( Hash ) at . delete ( path . last ) at [ yield ( path . last ) ] = val end end else pathes . each do | path | Algo . visit ( @hash , path ) do | at , pth , val | Algo . delete ( at , pth . last ) at [ yield ( pth . last ) ] = val end end end self end
Performs specified transformations on keys of input sequence, optionally limited only by specified
pathes.
Performs specified transformations on keys of input sequence optionally limited only by specified pathes .
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 .
key
Current key to process.
Current key to process .
example
None
see
None
see
None