Class: Robot::Matrix
- Inherits:
-
Object
- Object
- Robot::Matrix
- Defined in:
- lib/robot/matrix.rb
Constant Summary collapse
- DIRECTION_ARROWS =
{ north: '^', east: '>', south: 'v', west: '<' }
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#matrix ⇒ Object
Returns the value of attribute matrix.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(position, direction) ⇒ Matrix
constructor
A new instance of Matrix.
-
#to_s ⇒ Object
puts an arrow pointing in the direction of the current x,y of the robot on a matrix and returns a string of the matrix.
Constructor Details
#initialize(position, direction) ⇒ Matrix
Returns a new instance of Matrix.
13 14 15 16 17 |
# File 'lib/robot/matrix.rb', line 13 def initialize(position, direction) @position = position @direction = direction @matrix = generate_matrix end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
3 4 5 |
# File 'lib/robot/matrix.rb', line 3 def direction @direction end |
#matrix ⇒ Object
Returns the value of attribute matrix.
4 5 6 |
# File 'lib/robot/matrix.rb', line 4 def matrix @matrix end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
3 4 5 |
# File 'lib/robot/matrix.rb', line 3 def position @position end |
Instance Method Details
#to_s ⇒ Object
puts an arrow pointing in the direction of the current x,y of the robot on a matrix and returns a string of the matrix
22 23 24 25 |
# File 'lib/robot/matrix.rb', line 22 def to_s set_current_position! matrix.reverse.map { |row| row.join(' ') }.join("\n") end |