views:

34

answers:

1

Hey,

given this code:

class A
  CONST = 'A'

  def initialize
    puts CONST
  end
end

class B < A
  CONST = 'B'
end

A.new # => 'A'
B.new # => 'A'

I'd like B to use the CONST = 'B' definition, but I don't know how. Any ideas?

Greetings

Tom

+5  A: 
class A
  CONST = 'A'

  def initialize
    puts self.class::CONST
  end
end

class B < A
  CONST = 'B'
end

A.new # => 'A'
B.new # => 'B'
Konstantin Haase
Perfect, thanks a lot!
Tom
@Tom: If it's perfect, why not accept the answer?
Lars Haugseth