lib/hm.rb
# Split hash into two: the one with the substructure matching `pathes`, and the with thos that do
# not.
#
# @example
#   order = {items: [{title: "Beef", price: 18.0}, {title: "Potato", price: 8.2}], total: 26.2}
#   Hm(order).partition(%i[items * price], :total)
#   # => [
#   #  {:items=>[{:price=>18.0}, {:price=>8.2}], :total=>26.2},
#   #  {:items=>[{:title=>"Beef"}, {:title=>"Potato"}]}
#   # ]
#
# @param pathes [Array] List of pathes (each being singular key, or array of keys, including
#   `:*` wildcard) to look at.
# @yieldparam value [Array] Current value to process.
# @return [Array<Hash>] Two hashes
Split hash into two: the one with the substructure matching `pathes`, and the with thos that do
not.
Split hash into two : the one with the substructure matching ` pathes ` and the with thos that do not .
def partition(*pathes)
    [
      Hm(@hash).slice(*pathes).to_h,
      Hm(@hash).except(*pathes).to_h
    ]
  end
def partition ( * pathes ) [ Hm ( @hash ) . slice ( * pathes ) . to_h , Hm ( @hash ) . except ( * pathes ) . to_h ] end
Split hash into two: the one with the substructure matching `pathes`, and the with thos that do
not.
Split hash into two : the one with the substructure matching ` pathes ` and the with thos that do not .
# FIXME: this implementation is naive, it performs 2 additional deep copies and 2 full cycles of # visiting instead of just splitting existing data in one pass. It works, though
None
Array<Hash>
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 .
value
Current value to process.
Current value to process .
example
None