Resolving clashing code from merge

This commit is contained in:
Maruno17
2022-11-05 21:10:05 +00:00
parent 3e73d1c1f9
commit 55563463d8

View File

@@ -96,15 +96,11 @@ end
#=============================================================================== #===============================================================================
class HandlerHash class HandlerHash
def initialize def initialize
@hash = {} @hash = {}
@add_ifs = []
end end
def [](id) def [](id)
return @hash[id] if id && @hash[id] return @hash[id] if id && @hash[id]
@add_ifs.each do |add_if|
return add_if[2] if add_if[1].call(id)
end
return nil return nil
end end
@@ -115,13 +111,6 @@ class HandlerHash
@hash[id] = handler || handlerBlock if id && !id.empty? @hash[id] = handler || handlerBlock if id && !id.empty?
end end
def add_if(id, conditionProc, handler = nil, &handlerBlock)
if ![Proc, Hash].include?(handler.class) && !block_given?
raise ArgumentError, "add_if call for #{self.class.name} has no valid handler (#{handler.inspect} was given)"
end
@add_ifs.push([id, conditionProc, handler || handlerBlock])
end
def copy(src, *dests) def copy(src, *dests)
handler = self[src] handler = self[src]
return if !handler return if !handler
@@ -129,16 +118,11 @@ class HandlerHash
end end
def remove(key) def remove(key)
if @hash.keys.include?(key) @hash.delete(key)
@hash.delete(key)
else
@add_ifs.delete_if { |add_if| add_if[0] == key }
end
end end
def clear def clear
@hash.clear @hash.clear
@add_ifs.clear
end end
def each def each
@@ -158,7 +142,8 @@ end
#=============================================================================== #===============================================================================
# A stripped-down version of class HandlerHash which only deals with IDs that # A stripped-down version of class HandlerHash which only deals with IDs that
# are symbols. # are symbols. Also contains an add_ifs hash for code that applies to multiple
# IDs (determined by its condition proc).
#=============================================================================== #===============================================================================
class HandlerHashSymbol class HandlerHashSymbol
def initialize def initialize
@@ -271,6 +256,13 @@ class HandlerHashEnum
@hash[symbol] = handler || handlerBlock if symbol @hash[symbol] = handler || handlerBlock if symbol
end end
def addIf(conditionProc, handler = nil, &handlerBlock)
if ![Proc, Hash].include?(handler.class) && !block_given?
raise ArgumentError, "addIf call for #{self.class.name} has no valid handler (#{handler.inspect} was given)"
end
@addIfs.push([conditionProc, handler || handlerBlock])
end
def copy(src, *dests) def copy(src, *dests)
handler = self[src] handler = self[src]
return if !handler return if !handler