Skip to content

Commit

Permalink
set periods, fixed hash.compact! header
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Greif committed Mar 2, 2013
1 parent 0711d7b commit f086a13
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions hobo_support/test/hobosupport/hash.rdoctest
Expand Up @@ -13,7 +13,7 @@ This is the Hash version of `Enumerable#select`. i.e. a way to create a new hash
>> {1=>2, 3=>4, 6=>5}.select_hash { |key, value| key < value }
=> {1=>2, 3=>4}

You can also give a block that takes one argument, in which case the block is given the value only
You can also give a block that takes one argument, in which case the block is given the value only.

>> {1=>2, 3=>4, 6=>5}.select_hash { |value| value != 2 }
=> {3=>4, 6=>5}
Expand All @@ -24,12 +24,12 @@ You can also give a block that takes one argument, in which case the block is gi
* `hash.map_hash { |key, value| block } => hash`
* `hash.map_hash { |value| block } => hash`

Applies a function to each *value* in a Hash, resulting in a new hash with the same keys but new values. The block is passed each key, value pair and should return the new value
Applies a function to each *value* in a Hash, resulting in a new hash with the same keys but new values. The block is passed each key, value pair and should return the new value.

>> {1=>2, 3=>4, 6=>5}.map_hash { |key, value| key < value }
=> {1=>true, 3=>true, 6=>false}

You can also give a block which takes one argument, in which case only the value is passed in
You can also give a block which takes one argument, in which case only the value is passed in.

>> {1=>2, 3=>4, 6=>5}.map_hash { |value| value * 100 }
=> {1=>200, 3=>400, 6=>500 }
Expand All @@ -40,12 +40,12 @@ You can also give a block which takes one argument, in which case only the value
* `hash.partition_hash(keys) => [hash1, hash2]`
* `hash.partition_hash { |key, value| block } => hash`

Returns an array of two hashes, the first with all the key/value pairs where the key was in passed Enumerable, the second with the remaining key/value pairs
Returns an array of two hashes, the first with all the key/value pairs where the key was in passed Enumerable, the second with the remaining key/value pairs.

>> {1=>2, 3=>4, 6=>5}.partition_hash([1, 3])
=> [{1=>2, 3=>4}, {6=>5}]

When passed a block, each pair is passed to the block in turn. The result is two hashes, the first containing those pairs for which the block returned true, the second with the remaining pairs
When passed a block, each pair is passed to the block in turn. The result is two hashes, the first containing those pairs for which the block returned true, the second with the remaining pairs.

>> {1=>2, 3=>4, 6=>5}.partition_hash { |key, value| key < value }
=> [{1=>2, 3=>4}, {6=>5}]
Expand All @@ -54,7 +54,7 @@ When passed a block, each pair is passed to the block in turn. The result is two

* `hash.recursive_update(hash2)`

Like `#update` but where a sub-hash would overwrite another sub-hash, they are instead also merged, recursively
Like `#update` but where a sub-hash would overwrite another sub-hash, they are instead also merged, recursively.

>> h = { :a => 1, :b => { :x => 10 } }
>> h.recursive_update({ :c => 3, :b => { :y => 20 } })
Expand All @@ -75,7 +75,7 @@ Returns a new hash, the left-hand-side hash with all pairs removed where the key

* `hash & array => array`

Returns a new array, the left hand side hash restricted to pairs where the key is present in the right-hand-side array
Returns a new array, the left hand side hash restricted to pairs where the key is present in the right-hand-side array.

>> {1=>2, 3=>4, 6=>5} & [1, 3]
=> {1=>2, 3=>4}
Expand All @@ -84,7 +84,7 @@ Returns a new array, the left hand side hash restricted to pairs where the key i

* `hash | hash => hash`

An alias for merge
An alias for merge.

>> {1 => 2} | {1 => 3, 2 => 4}
=> {1 => 3, 2 => 4}
Expand All @@ -103,16 +103,16 @@ Returns an array of values for the given keys. Useful for extracting a few optio

* `hash.compact => hash`

Returns a hash with the same items as the receiver except those where the value is nil
Returns a hash with the same items as the receiver except those where the value is nil.

>> {1=>'a', 2=>nil, 3=>'b'}.compact
=> {1=>'a', 3=>'b'}

## `Hash#compact`
## `Hash#compact!`

* `hash.compact!`

Removes every pair from the hash where the value is nil
Removes every pair from the hash where the value is nil.

>> h = {1=>'a', 2=>nil, 3=>'b'}
>> h.compact!
Expand Down

0 comments on commit f086a13

Please sign in to comment.