the dragon has-a traits object


T

Thufir

Is this the "correct" way to change the dragon's traits?


C:\code>
C:\code>
C:\code>composition.rb
#<Dragon:0x277057c>

C:\code>
C:\code>
C:\code>dir
Volume in drive C has no label.
Volume Serial Number is 0491-510F

Directory of C:\code

11/13/2007 01:36 PM <DIR> .
11/13/2007 01:36 PM <DIR> ..
11/13/2007 01:48 PM 81 composition.rb
11/13/2007 01:49 PM 156 Creature.rb
11/13/2007 01:46 PM 117 Dragon.rb
11/13/2007 01:47 PM 246 Traits.rb
4 File(s) 600 bytes
2 Dir(s) 30,947,139,584 bytes free

C:\code>
C:\code>type composition.rb
require 'Dragon'


drgn = Dragon.new

drgn.traits.life = 1340


puts drgn
C:\code>
C:\code>type Dragon.rb
require 'Creature'

class Dragon < Creature

def initialize ()
super
end

def inspect ()
super
end

end
C:\code>
C:\code>type Creature.rb
require 'Traits'

class Creature

attr_accessor :traits


def initialize ()
@traits=Traits.new
end

def inspect ()
@traits.inspect
end

end
C:\code>
C:\code>type Traits.rb
class Traits

attr_accessor :life, :strength, :charisma, :weapon

def initialize ()
@life = 0
@strength = 0
@charisma = 0
@weapon = 0
end

def inspect ()
puts @life
puts @strength
puts @charisma
puts @weapon
end


end
C:\code>
C:\code>



thanks,

Thufir
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top