Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash_ext.rb
Instance Method Summary collapse
-
#partition(&block) ⇒ Object
similar to Enumerable partition() method, separate one hash into 2 based on the passed in test condition.
Instance Method Details
#partition(&block) ⇒ Object
similar to Enumerable partition() method, separate one hash into 2 based on the passed in test condition.
3 4 5 6 7 8 9 10 |
# File 'lib/hash_ext.rb', line 3 def partition(&block) h = dup h2 = {} each{|k, v| h2[k] = h.delete(k) if block.call(k,v) } [h2, h] end |