Class: KXI::Collections::HashCollection

Inherits:
Enumerable
  • Object
show all
Defined in:
lib/kxi/collections/hash_collection.rb

Overview

Makes hash enumerable. Every key-value pair of hash is represented by HashEnumerator::KeyValuePair class

Defined Under Namespace

Classes: HashEnumerator

Instance Method Summary collapse

Methods inherited from Enumerable

#aggregate, #all, #any, #can_alter?, #count, #enumerator, #first, #first!, #foreach, #last, #last!, #max, #min, #of_type, #of_type!, #order_by, #order_by_descending, #select, #select_many, #skip, #take, #to_array, #where

Constructor Details

#initialize(hash) ⇒ HashCollection

Instantiates the KXI::Collections::HashCollection class

Parameters:

  • hash (Hash)

    Hash for enumeration



10
11
12
13
# File 'lib/kxi/collections/hash_collection.rb', line 10

def initialize(hash)
	super()
	@hash = hash
end

Instance Method Details

#[](key) ⇒ Object

Gets value from hash at given key

Parameters:

  • key (Object)

    Key of value to obtain

Returns:

  • (Object)

    Obtained value



24
25
26
27
28
# File 'lib/kxi/collections/hash_collection.rb', line 24

def [](key)
	lock do
		return @hash[key]
	end
end

#[]=(key, value) ⇒ Object

Sets value to hash at given key

Parameters:

  • key (Object)

    Key of pair to set

  • value (Object)

    Value to set the pair to

Returns:

  • (Object)

    Given value



34
35
36
37
38
39
# File 'lib/kxi/collections/hash_collection.rb', line 34

def []=(key, value)
	lock(true) do
		@hash[key] = value
	end
	return value
end