Class: CowProxy::Hash
- Includes:
- Indexable, Enumerable
- Defined in:
- lib/cow_proxy/hash.rb
Overview
Wrapper class for Hash
Instance Method Summary collapse
-
#each {|pair| ... } ⇒ CowProxy::Hash, Enumerator
(also: #each_pair)
Calls block once for each key in hash, passing the key-value pair as parameters.
-
#each_value {|value| ... } ⇒ CowProxy::Hash, Enumerator
Calls block once for each key in hash, passing the value as parameter.
-
#hash ⇒ Intenger
Compute a hash-code for this hash.
-
#include?(key) ⇒ Array
Returns true if the given key is present in hash.
-
#reject {|pair| ... } ⇒ CowProxy::Hash, Enumerator
Returns a new hash consisting of entries for which the block returns false.
-
#select {|pair| ... } ⇒ CowProxy::Hash, Enumerator
Returns a new hash consisting of entries for which the block returns true.
-
#to_hash ⇒ Hash
Used for merging into another Hash needs to return unwrapped Hash.
-
#values ⇒ Array
Returns a new array populated with the wrapped values from hash.
Methods included from Indexable
Instance Method Details
#each {|pair| ... } ⇒ CowProxy::Hash, Enumerator Also known as: each_pair
Calls block once for each key in hash, passing the key-value pair as parameters.
15 16 17 18 19 20 |
# File 'lib/cow_proxy/hash.rb', line 15 def each return enum_for(:each) unless block_given? __getobj__.each_key do |k| yield [k, self[k]] end end |
#each_value {|value| ... } ⇒ CowProxy::Hash, Enumerator
Calls block once for each key in hash, passing the value as parameter.
29 30 31 32 |
# File 'lib/cow_proxy/hash.rb', line 29 def each_value return enum_for(:each) unless block_given? each { |_, v| yield v } end |
#hash ⇒ Intenger
Compute a hash-code for this hash. Two hashes with the same content will have the same hash code (and will compare using eql?).
82 83 84 |
# File 'lib/cow_proxy/hash.rb', line 82 def hash __getobj__.hash end |
#include?(key) ⇒ Array
Returns true if the given key is present in hash.
66 67 68 |
# File 'lib/cow_proxy/hash.rb', line 66 def include?(key) key?(key) end |
#reject {|pair| ... } ⇒ CowProxy::Hash, Enumerator
Returns a new hash consisting of entries for which the block returns false.
52 53 54 |
# File 'lib/cow_proxy/hash.rb', line 52 def reject ::Hash[super] end |
#select {|pair| ... } ⇒ CowProxy::Hash, Enumerator
Returns a new hash consisting of entries for which the block returns true.
41 42 43 |
# File 'lib/cow_proxy/hash.rb', line 41 def select ::Hash[super] end |
#to_hash ⇒ Hash
Used for merging into another Hash needs to return unwrapped Hash
74 75 76 |
# File 'lib/cow_proxy/hash.rb', line 74 def to_hash __getobj__ end |
#values ⇒ Array
Returns a new array populated with the wrapped values from hash.
59 60 61 |
# File 'lib/cow_proxy/hash.rb', line 59 def values map(&:last) end |