In this line you wrote

>   target.hp -= 200 # supposing target has methods #hp and #hp=


what is the meaning of the equal sign? #hp=

Because in my case above the target only has hp method.

And if I remodel it to your example:

def attack(target)
target.hp -= 200
end

class A
def initialize(name, hp)
@name = name
@hp = hp
end

def hp()
@hp
end

def name()
@name
end

end

players = [] << A.new("test", 400)

attack(players[0])
puts players[0].hp
-------------------------------------
3.rb:3:in `attack': undefined method `hp=' for #<A:0x8b7d268 
@name="test", @hp=400> (NoMethodError)
  from 3.rb:24:in `<main>'

-- 
Posted via http://www.ruby-forum.com/.