Class: ImmutableSet::SetChange
- Inherits:
-
Object
- Object
- ImmutableSet::SetChange
- Defined in:
- lib/values/immutable_set.rb
Instance Method Summary collapse
- #add_change_to_set(set) ⇒ Object
- #depth ⇒ Object
-
#initialize(values, set, add, set_change) ⇒ SetChange
constructor
A new instance of SetChange.
- #set ⇒ Object
- #unrole ⇒ Object
Constructor Details
#initialize(values, set, add, set_change) ⇒ SetChange
Returns a new instance of SetChange.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/values/immutable_set.rb', line 126 def initialize values,set,add,set_change raise "set must be supplied" unless set raise "values must be supplied" unless values @values = values @set = set @add = add @set_change = set_change @depth = 0 if set_change # We need to unrole when we have a depth of more than 500 so that we dont couse a SystemStackError if set_change.depth > 4000 @set_change = nil @set = set_change.unrole else @depth = set_change.depth + 1 end end end |
Instance Method Details
#add_change_to_set(set) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/values/immutable_set.rb', line 156 def add_change_to_set set @set_change.add_change_to_set(set) if @set_change if @add @values.each do |value| if value.is_a? ImmutableSet set.merge(value.to_a) elsif value.is_a? Set set.merge(value) elsif value.is_a? Array set.merge(value) else set.add(value) end end else @values.each do |value| if value.is_a? ImmutableSet set.subtract(value.to_a) elsif value.is_a? Set set.subtract(value) elsif value.is_a? Array set.subtract(value) else set.delete(value) end end end set end |
#depth ⇒ Object
152 153 154 |
# File 'lib/values/immutable_set.rb', line 152 def depth @depth end |
#set ⇒ Object
148 149 150 |
# File 'lib/values/immutable_set.rb', line 148 def set @set end |
#unrole ⇒ Object
189 190 191 |
# File 'lib/values/immutable_set.rb', line 189 def unrole self.add_change_to_set(@set.clone) end |