Class: Kwalify::Util::OrderedHash
- Inherits:
-
Hash
- Object
- Hash
- Kwalify::Util::OrderedHash
- Defined in:
- lib/kwalify/util/ordered-hash.rb
Instance Method Summary collapse
- #add(key, val) ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
-
#initialize(*args, &block) ⇒ OrderedHash
constructor
A new instance of OrderedHash.
-
#keys ⇒ Object
alias []= add.
- #put(key, val) ⇒ Object (also: #[]=)
- #values ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ OrderedHash
Returns a new instance of OrderedHash.
13 14 15 16 |
# File 'lib/kwalify/util/ordered-hash.rb', line 13 def initialize(*args, &block) super @_keys = [] end |
Instance Method Details
#add(key, val) ⇒ Object
25 26 27 28 29 |
# File 'lib/kwalify/util/ordered-hash.rb', line 25 def add(key, val) @_keys.delete_at(@_keys.index(key)) if self.key?(key) @_keys << key __set__(key, val) end |
#delete(key) ⇒ Object
42 43 44 45 |
# File 'lib/kwalify/util/ordered-hash.rb', line 42 def delete(key) @_keys.delete_at(@_keys.index(key)) if self.key?(key) super end |
#each ⇒ Object
47 48 49 50 51 |
# File 'lib/kwalify/util/ordered-hash.rb', line 47 def each @_keys.each do |key| yield key, self[key] end end |
#keys ⇒ Object
alias []= add
34 35 36 |
# File 'lib/kwalify/util/ordered-hash.rb', line 34 def keys return @_keys.dup end |
#put(key, val) ⇒ Object Also known as: []=
20 21 22 23 |
# File 'lib/kwalify/util/ordered-hash.rb', line 20 def put(key, val) @_keys << key unless self.key?(key) __set__(key, val) end |
#values ⇒ Object
38 39 40 |
# File 'lib/kwalify/util/ordered-hash.rb', line 38 def values return @_keys.collect {|key| self[key] } end |