On 16 апр, 03:25, Jesús Gabriel y Galán [email protected]
wrote:
   debug(@ini_health)
   warrior.attack!(cur_dir)
in the method, so i assume this is not what you want. When you do
Jesus.
Yes, “state” is assignment method. It behaves unsimiliar as other
languages:
“xxx=” can be declared in Object Pascal too, for example.
It seems local variable “state” has overriden my method “state”.
This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn’t give me any warning?
On Thu, Apr 15, 2010 at 10:00 PM, akraynov [email protected] wrote:
warrior.attack!(cur_dir)
end
then it executes “state = :ws_combat” normally.
Why it didn’t execute “state =” without “self”?
Is it Ruby’s bug?
I got Ruby 1.8 installed.
state = :ws_combat
is an assignment to a local variable. You are not using the variable
in the method, so i assume this is not what you want. When you do
self.state = :ws_combat
you are calling the method state= on the object, which I suppose you
have (maybe created by attr_accessor).
The fact that you have to call it this way is to disambiguate between
a local variable assignment and a method call with implicit receiver.
This is a consequence of the syntactic sugar that allows you have
methods name xxx= that look like assignments.
Jesus.
akraynov wrote:
It seems local variable “state” has overriden my method “state”.
This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn’t give me any warning?
Because it doesn’t parse incorrectly; it just runs incorrectly. That’s
why you need to do what Jesus explained.
The burden of intelligence is on the developer
On Fri, Apr 16, 2010 at 9:00 AM, akraynov [email protected] wrote:
   state = :ws_combat
   @ini_health = health
This is a consequence of the syntactic sugar that allows you have
methods name xxx= that look like assignments.
Jesus.
Yes, “state” is assignment method. It behaves unsimiliar as other
languages:
“xxx=” can be declared in Object Pascal too, for example.
It seems local variable “state” has overriden my method “state”.
Yes, that’s exactly what happens. The parser flags state as a local
variable, and not state= as a method call.
This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn’t give me any warning?
I don’t know.
Jesus.