Class: Robot::CommandProxy
- Inherits:
-
Object
- Object
- Robot::CommandProxy
- Defined in:
- lib/robot/command_proxy.rb
Overview
This class implements the proxy design pattern. It sits between the client and the commands, and only invokes the command if it passes validation.
Instance Attribute Summary collapse
-
#command_string ⇒ Object
readonly
Returns the value of attribute command_string.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(command_string:, position: nil) ⇒ CommandProxy
constructor
A new instance of CommandProxy.
Constructor Details
#initialize(command_string:, position: nil) ⇒ CommandProxy
Returns a new instance of CommandProxy.
9 10 11 12 |
# File 'lib/robot/command_proxy.rb', line 9 def initialize(command_string:, position: nil) @command_string = command_string @position = position end |
Instance Attribute Details
#command_string ⇒ Object (readonly)
Returns the value of attribute command_string.
7 8 9 |
# File 'lib/robot/command_proxy.rb', line 7 def command_string @command_string end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
7 8 9 |
# File 'lib/robot/command_proxy.rb', line 7 def position @position end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 |
# File 'lib/robot/command_proxy.rb', line 14 def call return if not_placed_yet? && !place_command? return position if would_fall? execute end |