Class: RubyLife::Cell
- Inherits:
-
Object
- Object
- RubyLife::Cell
- Defined in:
- lib/ruby_life/cell.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #dead? ⇒ Boolean
- #die! ⇒ Object
-
#initialize(status = nil) ⇒ Cell
constructor
A new instance of Cell.
- #live! ⇒ Object
- #to_s ⇒ Object
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
#status ⇒ Object (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
9 10 11 |
# File 'lib/ruby_life/cell.rb', line 9 def alive? @status == :alive end |
#dead? ⇒ 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_s ⇒ Object
25 26 27 |
# File 'lib/ruby_life/cell.rb', line 25 def to_s alive? ? "o" : "." end |