Class: ToyRobotSim::Location
- Inherits:
-
Object
- Object
- ToyRobotSim::Location
- Defined in:
- lib/toy_robot_sim/location.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #east ⇒ Object
-
#initialize(x, y) ⇒ Location
constructor
A new instance of Location.
- #north ⇒ Object
- #south ⇒ Object
- #west ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Location
Returns a new instance of Location.
5 6 7 8 9 10 11 12 13 |
# File 'lib/toy_robot_sim/location.rb', line 5 def initialize(x, y) if x.respond_to?(:to_i) && y.respond_to?(:to_i) @x = x.to_i @y = y.to_i else @x = 0 @y = 0 end end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'lib/toy_robot_sim/location.rb', line 3 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
3 4 5 |
# File 'lib/toy_robot_sim/location.rb', line 3 def y @y end |
Instance Method Details
#east ⇒ Object
21 22 23 |
# File 'lib/toy_robot_sim/location.rb', line 21 def east ToyRobotSim::Location.new(x + 1, y) end |
#north ⇒ Object
17 18 19 |
# File 'lib/toy_robot_sim/location.rb', line 17 def north ToyRobotSim::Location.new(x, y + 1) end |
#south ⇒ Object
25 26 27 |
# File 'lib/toy_robot_sim/location.rb', line 25 def south ToyRobotSim::Location.new(x, y - 1) end |
#west ⇒ Object
29 30 31 |
# File 'lib/toy_robot_sim/location.rb', line 29 def west ToyRobotSim::Location.new(x - 1, y) end |