Class: Kwaff::OrderedHash
- Inherits:
-
Object
- Object
- Kwaff::OrderedHash
- Includes:
- Enumerable
- Defined in:
- lib/kwaff/orderedhash.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #default ⇒ Object
- #default=(value) ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ OrderedHash
constructor
A new instance of OrderedHash.
- #key?(key) ⇒ Boolean
Constructor Details
#initialize ⇒ OrderedHash
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
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
19 20 21 |
# File 'lib/kwaff/orderedhash.rb', line 19 def hash @hash end |
#keys ⇒ Object (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 |
#default ⇒ Object
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
50 51 52 |
# File 'lib/kwaff/orderedhash.rb', line 50 def key?(key) return @hash.key?(key) end |