Class: RubyLife::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_life/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status = nil) ⇒ Cell

Returns a new instance of Cell.



5
6
7
# File 'lib/ruby_life/cell.rb', line 5

def initialize(status = nil)
  @status = status || [:alive, :dead].sample
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/ruby_life/cell.rb', line 3

def status
  @status
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/ruby_life/cell.rb', line 9

def alive?
  @status == :alive
end

#dead?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/ruby_life/cell.rb', line 13

def dead?
  @status == :dead
end

#die!Object



17
18
19
# File 'lib/ruby_life/cell.rb', line 17

def die!
  @status = :dead
end

#live!Object



21
22
23
# File 'lib/ruby_life/cell.rb', line 21

def live!
  @status = :alive
end

#to_sObject



25
26
27
# File 'lib/ruby_life/cell.rb', line 25

def to_s
  alive? ? "o" : "."
end