Class: Toy::Unit
- Inherits:
-
Object
- Object
- Toy::Unit
- Defined in:
- lib/toy/unit.rb
Defined Under Namespace
Modules: Error
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #hold!(object) ⇒ Object
-
#initialize(x, y, table = Toy::Table.new) ⇒ Unit
constructor
A new instance of Unit.
- #release! ⇒ Object
Constructor Details
#initialize(x, y, table = Toy::Table.new) ⇒ Unit
Returns a new instance of Unit.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/toy/unit.rb', line 7 def initialize(x, y, table=Toy::Table.new) raise Toy::Unit::Error::CoordinateError unless x.is_a?(Fixnum) raise Toy::Unit::Error::CoordinateError unless y.is_a?(Fixnum) raise Toy::Unit::Error::TableError unless table.is_a?(Table) @table = table @x = x @y = y @object = nil end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/toy/unit.rb', line 5 def object @object end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
5 6 7 |
# File 'lib/toy/unit.rb', line 5 def table @table end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
5 6 7 |
# File 'lib/toy/unit.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
5 6 7 |
# File 'lib/toy/unit.rb', line 5 def y @y end |
Instance Method Details
#available? ⇒ Boolean
26 27 28 |
# File 'lib/toy/unit.rb', line 26 def available? @object.nil? end |
#hold!(object) ⇒ Object
18 19 20 |
# File 'lib/toy/unit.rb', line 18 def hold!(object) @object = object end |
#release! ⇒ Object
22 23 24 |
# File 'lib/toy/unit.rb', line 22 def release! @object = nil end |