Class: Gene::Slice
- Inherits:
-
Object
- Object
- Gene::Slice
- Defined in:
- lib/kittyverse/gene.rb
Overview
todo/check:
find a better name for Slice(incl.4 genes)
e.g. GeneFour, Gene4, GeneGroup, GeneSlice,TraitGenes,... - why? why not?
Instance Attribute Summary collapse
-
#d ⇒ Object
(also: #d0, #p)
readonly
Returns the value of attribute d.
-
#r1 ⇒ Object
(also: #h1)
readonly
Returns the value of attribute r1.
-
#r2 ⇒ Object
(also: #h2)
readonly
Returns the value of attribute r2.
-
#r3 ⇒ Object
(also: #h3)
readonly
Returns the value of attribute r3.
-
#type ⇒ Object
readonly
Gene::Slice (nested class).
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(type, d, r1, r2, r3) ⇒ Slice
constructor
A new instance of Slice.
- #purebred? ⇒ Boolean (also: #pure?)
- #to_kai ⇒ Object
Constructor Details
#initialize(type, d, r1, r2, r3) ⇒ Slice
Returns a new instance of Slice.
26 27 28 29 30 31 32 |
# File 'lib/kittyverse/gene.rb', line 26 def initialize( type, d, r1, r2, r3 ) @type = TraitType[type] ## lookup trait type by key (e.g. :body, :pattern, etc.) @d = @type[d] ## lookup trait (from trait type) by kai code (e.g. "1", "a", etc.) @r1 = @type[r1] @r2 = @type[r2] @r3 = @type[r3] end |
Instance Attribute Details
#d ⇒ Object (readonly) Also known as: d0, p
Returns the value of attribute d.
11 12 13 |
# File 'lib/kittyverse/gene.rb', line 11 def d @d end |
#r1 ⇒ Object (readonly) Also known as: h1
Returns the value of attribute r1.
11 12 13 |
# File 'lib/kittyverse/gene.rb', line 11 def r1 @r1 end |
#r2 ⇒ Object (readonly) Also known as: h2
Returns the value of attribute r2.
11 12 13 |
# File 'lib/kittyverse/gene.rb', line 11 def r2 @r2 end |
#r3 ⇒ Object (readonly) Also known as: h3
Returns the value of attribute r3.
11 12 13 |
# File 'lib/kittyverse/gene.rb', line 11 def r3 @r3 end |
#type ⇒ Object (readonly)
Gene::Slice (nested class)
10 11 12 |
# File 'lib/kittyverse/gene.rb', line 10 def type @type end |
Instance Method Details
#[](index) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/kittyverse/gene.rb', line 34 def [](index) case index when 0 then @d when 1 then @r1 when 2 then @r2 when 3 then @r3 else nil ## return nil for unknown index for now (raise except - why? why not?) end end |
#purebred? ⇒ Boolean Also known as: pure?
44 |
# File 'lib/kittyverse/gene.rb', line 44 def purebred?() @d == @r1 && @d == @r2 && @d == @r3; end |
#to_kai ⇒ Object
48 49 50 |
# File 'lib/kittyverse/gene.rb', line 48 def to_kai @r3.kai + @r2.kai + @r1.kai + @d.kai end |