On 07/11/2012 08:21 AM, Sebastjan H. wrote:
> Thank you for the clarification. I understand the difference and I have
> to first fully determine the logic and the mechanics I want and then
> adjust the code.
>
> One side note, why this: puts "#{beast} strikes with: " produces this:
> #<Blue_Scale_DRAGON:0x8a225d0>  strikes with:?
>
> I am guessing it has to with the class, but would I get the actual name
> of the beast which dealt the damage?
>
> regards
> seba
>
You could define a #to_s method on your dragon class, in which case you 
would probably see what you want in that string interpolation. It might 
return the @name as a string, or some human readable representation of 
the class like "Blue Scale Dragon" depending on what you want the output 
to say. A better approach might be to use your existing #dragon_name 
method in the interpolation like so;

"#{beast.dragon_name}"

You might decide this is a bit clunky and change that method to simply 
#name which makes it a bit more convenient when displaying messages 
about various different beast instances without having to know which 
kind of beast they are. If you were to do this, your definition could 
become;

attr_reader :name

to be called like;

"#{beast.name}"

You could take it a step further and have a base Beast class which 
defines all the common methods and attributes of a beast, and then make 
the Blue Scale Dragon a subclass.

BlueScaleDragon < Beast

So many possibilities, hope that helps!

http://ruby-doc.org/core-1.9.3/Module.html#method-i-attr_reader


Sam