class Robot::Table
Attributes
height[R]
position[RW]
width[R]
Public Class Methods
new()
click to toggle source
# File lib/robot/table.rb, line 10 def initialize @width = 4 @height = 4 end
Public Instance Methods
place(x, y)
click to toggle source
# File lib/robot/table.rb, line 15 def place(x, y) position = { x: x.to_i, y: y.to_i } self.position = position if valid_position?(position) end
placed?()
click to toggle source
# File lib/robot/table.rb, line 20 def placed? !position.nil? end
valid_position?(position)
click to toggle source
# File lib/robot/table.rb, line 24 def valid_position?(position) position[:x] <= width && position[:x] >= 0 && \ position[:y] <= height && position[:y] >= 0 end