Class: TransactionArray
- Inherits:
-
Object
- Object
- TransactionArray
- Defined in:
- lib/crdt/tgcounter.rb
Overview
Ease of use class - Wraps an ordered array with some hash-like functions
Instance Attribute Summary collapse
-
#arr ⇒ Object
Returns the value of attribute arr.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(arr = Array.new()) ⇒ TransactionArray
constructor
A new instance of TransactionArray.
- #length ⇒ Object
Constructor Details
#initialize(arr = Array.new()) ⇒ TransactionArray
Returns a new instance of TransactionArray.
191 192 193 |
# File 'lib/crdt/tgcounter.rb', line 191 def initialize(arr=Array.new()) self.arr = arr end |
Instance Attribute Details
#arr ⇒ Object
Returns the value of attribute arr.
189 190 191 |
# File 'lib/crdt/tgcounter.rb', line 189 def arr @arr end |
Instance Method Details
#==(other) ⇒ Object
199 200 201 |
# File 'lib/crdt/tgcounter.rb', line 199 def ==(other) self.arr == other.arr end |
#[](key) ⇒ Object
208 209 210 211 |
# File 'lib/crdt/tgcounter.rb', line 208 def [](key) res = self.arr.select { |a| a[0] == key } res.first[1] if res && res.length > 0 &&res.first.length == 2 end |
#[]=(key, value) ⇒ Object
203 204 205 206 |
# File 'lib/crdt/tgcounter.rb', line 203 def []=(key, value) self.delete(key) if self.[](key) self.arr << [key, value] end |
#delete(key) ⇒ Object
213 214 215 216 |
# File 'lib/crdt/tgcounter.rb', line 213 def delete(key) index = self.arr.index { |a| a[0] == key } self.arr.delete_at(index) if index end |
#length ⇒ Object
195 196 197 |
# File 'lib/crdt/tgcounter.rb', line 195 def length() self.arr.length end |