motion/core/kvo.rb in bubble-wrap-1.3.0 vs motion/core/kvo.rb in bubble-wrap-1.4.0

- old
+ new

@@ -62,32 +62,30 @@ def remove_observer_block(target, key_path) return if @targets.nil? || target.nil? || key_path.nil? key_paths = @targets[target] - if !key_paths.nil? && key_paths.has_key?(key_path.to_s) - key_paths.delete(key_path.to_s) - end + key_paths.delete(key_path.to_s) if !key_paths.nil? end def remove_all_observer_blocks @targets.clear unless @targets.nil? end # NSKeyValueObserving Protocol - def observeValueForKeyPath(key_path, ofObject:target, change:change, context:context) + def observeValueForKeyPath(key_path, ofObject: target, change: change, context: context) key_paths = @targets[target] || {} - blocks = key_paths[key_path] || [] - blocks.each do |block| - args = [ change[NSKeyValueChangeOldKey], change[NSKeyValueChangeNewKey] ] - args << change[NSKeyValueChangeIndexesKey] if collection?(change) - block.call(*args) - end + blocks = key_paths[key_path] || [] + blocks.each do |block| + args = [change[NSKeyValueChangeOldKey], change[NSKeyValueChangeNewKey]] + args << change[NSKeyValueChangeIndexesKey] if collection?(change) + block.call(*args) end + end - def collection?(change) - COLLECTION_OPERATIONS.include?(change[NSKeyValueChangeKindKey]) - end + def collection?(change) + COLLECTION_OPERATIONS.include?(change[NSKeyValueChangeKindKey]) + end end end