Module: MiniFacet::Split

Defined in:
lib/mini_facet/hash/split.rb

Instance Method Summary collapse

Instance Method Details

#split(&block) ⇒ Object

Returns two hashes. The first contains all pairs for which the block evaluated to true, the second contains all the others.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mini_facet/hash/split.rb', line 4

def split(&block)
  trues, falses = self.class.new, self.class.new
  each_pair do |k,v| 
    if yield(k,v) 
      trues[k] = v
    else
      falses[k] = v
    end
  end
  #each_pair{ |k,v| (yield(k,v) ? trues : falses)[k] = v }
  return trues, falses
end