I want to put all of the current attr_accessor’s
(:life, :strength, :charisma, :weapon) into class Traits so that each
Creature instance will have one Traits object to go along with that
class.
by themselves, Traits, Dragon and Class give no error messages from
ruby. From using the IRB it’s clear that it’s line 6 of the Dragon
class:
@traits.life = 1340
C:\code\creat3>
C:\code\creat3>
C:\code\creat3>creatures.rb
./Dragon.rb:6:in initialize': undefined method
life=’ for
nil:NilClass (NoMeth
odError)
from C:/code/creat3/creatures.rb:12:in new' from C:/code/creat3/creatures.rb:12 from C:/code/creat3/creatures.rb:10:in
times’
from C:/code/creat3/creatures.rb:10
C:\code\creat3>
C:\code\creat3>
C:\code\creat3>type creatures.rb
require ‘ArrayOfCreatures’
require ‘MakeCreature’
require ‘Location’
include MakeCreature
NumOfCreatures=3
creatures = ArrayOfCreatures.instance
NumOfCreatures.times do |i|
creatures[i]=MakeCreature.randomCreature
creatures[i]=Dragon.new
end
creatures.length.times do |i|
number = Kernel.rand(6)
creatures.oneElementToString(i)
print “factorial of\t”
print number
print “\tis\t”
print Math.factorial(number)
end
C:\code\creat3>
C:\code\creat3>
C:\code\creat3>type Creature.rb
require ‘Math’
require ‘Traits’
class Creature
Creature.extend Math
include Math
def initialize ()
@location = Room.new
@traits = Traits.new
end
def toString ()
print “class\t\t”
print self.class
@attributes.toString
print "\n"
end
end
C:\code\creat3>
C:\code\creat3>type Dragon.rb
require ‘Creature’
class Dragon < Creature
def initialize ()
@traits.life = 1340
end
end
C:\code\creat3>
C:\code\creat3>
thanks,
Thufir