------------------------
class A
HELLO = "Hello I'm A"
def hello
puts HELLO
end
end
class B < A
HELLO = "Hello I'm B"
def hello2
puts HELLO
end
end
------------------------
B.new.hello
=> "Hello I'm A" (ouch...)
B.new.hello2
=> "Hello I'm B"
Workaround (but ugly):
-----------------
class A
def hello
puts self.class::HELLO
end
end
-----------------
So, if a contstant appears within a method, its value is evaluated for
the class in which such method is defined ("hello" is defined in class
A not in B, so it takes HELLO from class A).
I don't like this behavior (just my opinion). Do I miss something?
Regards.
--
IƱaki Baz Castillo
<ibc / aliax.net>