class Patterns::ChainNode

ChainNode -> Object

Will likely be refactored to be more abstract, currently this class has a reliance on the “see_patient” method existing in our node, which isn't a great thing

Attributes

next_node[RW]

The next node in the list, or nil if it does not exist

Public Class Methods

new(next_node = nil) click to toggle source

Initializes the ChainNode and sets the next node to another chain object or nil

# File app/models/chain_of_responsibility/chain_node.rb, line 10
def initialize(next_node = nil)
  @next_node = next_node
end

Public Instance Methods

process(argument) click to toggle source
# File app/models/chain_of_responsibility/chain_node.rb, line 23
def process(argument)
  puts "#{self} received argument: #{argument}, this should be overloaded in a subclass."
end
send_up_chain(argument) click to toggle source

Delegates the responsibility to the next node in the chain

# File app/models/chain_of_responsibility/chain_node.rb, line 15
def send_up_chain(argument)
  if @next_node != nil
  @next_node.process(argument)
  else
    'We found patient zero! AHHHH ZOMBIES!!!'
  end
end