Class: Gene::Slice

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

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

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

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

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

#typeObject (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?

Returns:

  • (Boolean)


44
# File 'lib/kittyverse/gene.rb', line 44

def purebred?() @d == @r1 && @d == @r2 && @d == @r3; end

#to_kaiObject



48
49
50
# File 'lib/kittyverse/gene.rb', line 48

def to_kai
  @r3.kai + @r2.kai + @r1.kai + @d.kai
end