Class: Meangirls::LWWSet::Pair
- Inherits:
-
Object
- Object
- Meangirls::LWWSet::Pair
- Defined in:
- lib/meangirls/lww_set.rb
Instance Attribute Summary collapse
-
#add ⇒ Object
Returns the value of attribute add.
-
#remove ⇒ Object
Returns the value of attribute remove.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #exists_a? ⇒ Boolean
- #exists_r? ⇒ Boolean
-
#initialize(add, remove) ⇒ Pair
constructor
A new instance of Pair.
- #inspect ⇒ Object
-
#merge(other) ⇒ Object
(also: #|)
Merge with another pair, taking the largest add and largest delete stamp.
Constructor Details
#initialize(add, remove) ⇒ Pair
Returns a new instance of Pair.
6 7 8 9 |
# File 'lib/meangirls/lww_set.rb', line 6 def initialize(add, remove) @add = add @remove = remove end |
Instance Attribute Details
#add ⇒ Object
Returns the value of attribute add.
5 6 7 |
# File 'lib/meangirls/lww_set.rb', line 5 def add @add end |
#remove ⇒ Object
Returns the value of attribute remove.
5 6 7 |
# File 'lib/meangirls/lww_set.rb', line 5 def remove @remove end |
Instance Method Details
#==(o) ⇒ Object
11 12 13 14 15 |
# File 'lib/meangirls/lww_set.rb', line 11 def ==(o) o.kind_of? Pair and add == o.add and remove == o.remove end |
#exists_a? ⇒ Boolean
17 18 19 20 21 |
# File 'lib/meangirls/lww_set.rb', line 17 def exists_a? return false unless @add return true unless @remove @add >= @remove end |
#exists_r? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/meangirls/lww_set.rb', line 23 def exists_r? return false unless @add return true unless @remove @add > @remove end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/meangirls/lww_set.rb', line 29 def inspect "(#{add.inspect}, #{remove.inspect})" end |
#merge(other) ⇒ Object Also known as: |
Merge with another pair, taking the largest add and largest delete stamp.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meangirls/lww_set.rb', line 34 def merge(other) unless other return clone end Pair.new( [add, other.add].compact.max, [remove, other.remove].compact.max ) end |