Class: Toy::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/toy/unit.rb

Defined Under Namespace

Modules: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/toy/unit.rb', line 5

def object
  @object
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/toy/unit.rb', line 5

def table
  @table
end

#xObject (readonly)

Returns the value of attribute x.



5
6
7
# File 'lib/toy/unit.rb', line 5

def x
  @x
end

#yObject (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

Returns:

  • (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