class CowProxy::Hash

Wrapper class for Hash

Public Instance Methods

each() { |k, self| ... } click to toggle source

Calls block once for each key in hash, passing the key-value pair as parameters.

@yield [pair] Gives each key-value pair in self to the block @yieldparam pair Array of key and wrapped value @return [CowProxy::Hash] self if block given @return [Enumerator] if no block given

# 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
Also aliased as: each_pair
each_pair()
Alias for: each
each_value() { |v| ... } click to toggle source

Calls block once for each key in hash, passing the value as parameter.

@yield [value] Gives each value in hash to the block @yieldparam value Wrapped value @return [CowProxy::Hash] self if block given @return [Enumerator] if no block given

# File lib/cow_proxy/hash.rb, line 29
def each_value
  return enum_for(:each) unless block_given?
  each { |_, v| yield v }
end
hash() click to toggle source

Compute a hash-code for this hash. Two hashes with the same content will have the same hash code (and will compare using eql?).

@return [Intenger] calculated hash code

# File lib/cow_proxy/hash.rb, line 82
def hash
  __getobj__.hash
end
include?(key) click to toggle source

Returns true if the given key is present in hash.

@return [Array] Wrapped values from hash

# File lib/cow_proxy/hash.rb, line 66
def include?(key)
  key?(key)
end
reject() click to toggle source

Returns a new hash consisting of entries for which the block returns false.

@yield [pair] Gives each key-value pair in self to the block @yieldparam pair Array of key and wrapped value @yieldreturn [Boolean] true if item must not be included @return [CowProxy::Hash] self if block given @return [Enumerator] if no block given

# File lib/cow_proxy/hash.rb, line 52
def reject
  ::Hash[super]
end
select() click to toggle source

Returns a new hash consisting of entries for which the block returns true.

@yield [pair] Gives each key-value pair in self to the block @yieldparam pair Array of key and wrapped value @yieldreturn [Boolean] true if item must be included @return [CowProxy::Hash] self if block given @return [Enumerator] if no block given

# File lib/cow_proxy/hash.rb, line 41
def select
  ::Hash[super]
end
to_hash() click to toggle source

Used for merging into another Hash needs to return unwrapped Hash

@return [Hash] wrapped object

# File lib/cow_proxy/hash.rb, line 74
def to_hash
  __getobj__
end
values() click to toggle source

Returns a new array populated with the wrapped values from hash.

@return [Array] Wrapped values from hash

# File lib/cow_proxy/hash.rb, line 59
def values
  map(&:last)
end