Class: ChainOfResponsibility::Handler
- Inherits:
-
Object
- Object
- ChainOfResponsibility::Handler
- Defined in:
- lib/chain_of_responsibility/handler.rb
Instance Attribute Summary collapse
-
#successor ⇒ Object
readonly
Returns the value of attribute successor.
Instance Method Summary collapse
- #applicable? ⇒ Boolean
- #call(*args) ⇒ Object
-
#initialize(successor = MissingSuccessor.new) ⇒ Handler
constructor
A new instance of Handler.
- #resolve ⇒ Object
Constructor Details
#initialize(successor = MissingSuccessor.new) ⇒ Handler
Returns a new instance of Handler.
8 9 10 |
# File 'lib/chain_of_responsibility/handler.rb', line 8 def initialize(successor = MissingSuccessor.new) @successor = successor end |
Instance Attribute Details
#successor ⇒ Object (readonly)
Returns the value of attribute successor.
12 13 14 |
# File 'lib/chain_of_responsibility/handler.rb', line 12 def successor @successor end |
Instance Method Details
#applicable? ⇒ Boolean
26 27 28 |
# File 'lib/chain_of_responsibility/handler.rb', line 26 def applicable?(*) raise MethodNotImplementedError, "applicable?" end |
#call(*args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/chain_of_responsibility/handler.rb', line 14 def call(*args) if applicable?(*args) resolve(*args) else successor.call(*args) end end |
#resolve ⇒ Object
22 23 24 |
# File 'lib/chain_of_responsibility/handler.rb', line 22 def resolve(*) raise MethodNotImplementedError, "resolve" end |