Class: C4::Model::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/c4/model/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ Column

Returns a new instance of Column.



13
14
15
16
# File 'lib/c4/model/column.rb', line 13

def initialize(max_size)
  @stones = []
  @max_size = max_size
end

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size.



11
12
13
# File 'lib/c4/model/column.rb', line 11

def max_size
  @max_size
end

#stonesObject (readonly)

Returns the value of attribute stones.



11
12
13
# File 'lib/c4/model/column.rb', line 11

def stones
  @stones
end

Instance Method Details

#full?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/c4/model/column.rb', line 24

def full?
  stones.size >= max_size
end

#put!(mark) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/c4/model/column.rb', line 18

def put!(mark)
  raise ColumnFullError, 'This column is full!' if full?

  stones.push(mark)
end

#to_aObject



28
29
30
# File 'lib/c4/model/column.rb', line 28

def to_a
  stones.fill_up_to(max_size, nil)
end