Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > the dragon has-a traits object

Reply
Thread Tools

the dragon has-a traits object

 
 
Thufir
Guest
Posts: n/a
 
      11-13-2007
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to generate execute file that include enthought.traits.api ,enthought.traits.ui.api ? ray Python 1 06-04-2010 03:49 PM
Dragon NaturallySpeaking 8 XhArD The Lounge 29 03-12-2006 06:33 AM
FrozenCPU ThermalRock Dragon Alphacool Review @ Virtual-Hideout Silverstrand Front Page News 0 02-25-2006 10:05 PM
MGE XG Dragon Gaming Case Silverstrand Front Page News 0 12-29-2005 11:32 PM
OT Friday Fun, just for Dragon Consultant MCSE 5 12-12-2003 10:11 PM



Advertisments