Class: CassandraClient::OrderedHash
- Inherits:
-
Hash
- Object
- Hash
- CassandraClient::OrderedHash
- Defined in:
- lib/cassandra_client/ordered_hash.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #delete_if ⇒ Object
- #each ⇒ Object (also: #each_pair)
- #each_key ⇒ Object
- #each_value ⇒ Object
-
#initialize(*args, &block) ⇒ OrderedHash
constructor
A new instance of OrderedHash.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #keys ⇒ Object
- #merge(other_hash) ⇒ Object
- #merge!(other_hash) ⇒ Object
- #reject(&block) ⇒ Object
- #reject! ⇒ Object
- #shift ⇒ Object
- #to_hash ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ OrderedHash
Returns a new instance of OrderedHash.
36 37 38 39 |
# File 'lib/cassandra_client/ordered_hash.rb', line 36 def initialize(*args, &block) super @keys = [] end |
Class Method Details
.[](*array) ⇒ Object
30 31 32 33 34 |
# File 'lib/cassandra_client/ordered_hash.rb', line 30 def self.[](*array) hash = new array.each_slice(2) { |key, value| hash[key] = value } hash end |
Instance Method Details
#[]=(key, value) ⇒ Object
47 48 49 50 |
# File 'lib/cassandra_client/ordered_hash.rb', line 47 def []=(key, value) @keys << key if !has_key?(key) super end |
#clear ⇒ Object
102 103 104 105 106 |
# File 'lib/cassandra_client/ordered_hash.rb', line 102 def clear super @keys.clear self end |
#delete(key) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/cassandra_client/ordered_hash.rb', line 52 def delete(key) if has_key? key index = @keys.index(key) @keys.delete_at index end super end |
#delete_if ⇒ Object
60 61 62 63 64 |
# File 'lib/cassandra_client/ordered_hash.rb', line 60 def delete_if super sync_keys! self end |
#each ⇒ Object Also known as: each_pair
96 97 98 |
# File 'lib/cassandra_client/ordered_hash.rb', line 96 def each @keys.each {|key| yield [key, self[key]]} end |
#each_key ⇒ Object
88 89 90 |
# File 'lib/cassandra_client/ordered_hash.rb', line 88 def each_key @keys.each { |key| yield key } end |
#each_value ⇒ Object
92 93 94 |
# File 'lib/cassandra_client/ordered_hash.rb', line 92 def each_value @keys.each { |key| yield self[key]} end |
#initialize_copy(other) ⇒ Object
41 42 43 44 45 |
# File 'lib/cassandra_client/ordered_hash.rb', line 41 def initialize_copy(other) super # make a deep copy of keys @keys = other.keys end |
#inspect ⇒ Object
123 124 125 |
# File 'lib/cassandra_client/ordered_hash.rb', line 123 def inspect "#<OrderedHash #{super}>" end |
#keys ⇒ Object
76 77 78 |
# File 'lib/cassandra_client/ordered_hash.rb', line 76 def keys @keys.dup end |
#merge(other_hash) ⇒ Object
119 120 121 |
# File 'lib/cassandra_client/ordered_hash.rb', line 119 def merge(other_hash) dup.merge!(other_hash) end |
#merge!(other_hash) ⇒ Object
114 115 116 117 |
# File 'lib/cassandra_client/ordered_hash.rb', line 114 def merge!(other_hash) other_hash.each {|k,v| self[k] = v } self end |
#reject(&block) ⇒ Object
72 73 74 |
# File 'lib/cassandra_client/ordered_hash.rb', line 72 def reject(&block) dup.reject!(&block) end |
#reject! ⇒ Object
66 67 68 69 70 |
# File 'lib/cassandra_client/ordered_hash.rb', line 66 def reject! super sync_keys! self end |
#shift ⇒ Object
108 109 110 111 112 |
# File 'lib/cassandra_client/ordered_hash.rb', line 108 def shift k = @keys.first v = delete(k) [k, v] end |
#to_hash ⇒ Object
84 85 86 |
# File 'lib/cassandra_client/ordered_hash.rb', line 84 def to_hash self end |
#values ⇒ Object
80 81 82 |
# File 'lib/cassandra_client/ordered_hash.rb', line 80 def values @keys.collect { |key| self[key] } end |