Class: Kwaff::OrderedHash

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kwaff/orderedhash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOrderedHash

Returns a new instance of OrderedHash.



14
15
16
17
# File 'lib/kwaff/orderedhash.rb', line 14

def initialize
	 @keys = []
	 @hash = {}
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



19
20
21
# File 'lib/kwaff/orderedhash.rb', line 19

def hash
  @hash
end

#keysObject (readonly)

Returns the value of attribute keys.



19
20
21
# File 'lib/kwaff/orderedhash.rb', line 19

def keys
  @keys
end

Instance Method Details

#[](key) ⇒ Object



28
29
30
# File 'lib/kwaff/orderedhash.rb', line 28

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

#[]=(key, value) ⇒ Object



32
33
34
35
# File 'lib/kwaff/orderedhash.rb', line 32

def []=(key, value)
	 @keys << key unless @hash.key?(key)
	 @hash[key] = value
end

#defaultObject



42
43
44
# File 'lib/kwaff/orderedhash.rb', line 42

def default
	 return @hash.default
end

#default=(value) ⇒ Object



46
47
48
# File 'lib/kwaff/orderedhash.rb', line 46

def default=(value)
	 @hash.default = value
end

#delete(key) ⇒ Object



37
38
39
40
# File 'lib/kwaff/orderedhash.rb', line 37

def delete(key)
	 @keys.delete(key)
	 @hash.delete(key)
end

#each(&block) ⇒ Object



21
22
23
24
25
26
# File 'lib/kwaff/orderedhash.rb', line 21

def each(&block)
	 keys.each do |key|
	    value = @hash[key]
	    yield(key, value)
	 end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/kwaff/orderedhash.rb', line 50

def key?(key)
	 return @hash.key?(key)
end