2011/8/14 Chris White <cwprogram / live.com>:
> This behavior can fortunately be overridden by simply overriding the hello method in the B class, meaning that it will use the constant defined in Binstead

Yes, but it requires duplicating code. In my case I've a server class:


class Server
  def self.foo
    puts "I listen in IP #{IP}"
  end
end


and then some classes inhereting from it:


class UdpServer < Server
  IP = "1.2.3.4"
end

class TcpServer < Server
  IP = "1.2.3.5"
end


Of course "TcpServer.foo" fails:

  NameError: uninitialized constant Server::IP


So I must use workarounds like:


class Server
  def self.foo
    puts "I listen in IP #{self::IP}"
  end
end

class UdpServer < Server
  IP = "1.2.3.4"
end

class TcpServer < Server
  IP = "1.2.3.5"
end


Then it works:


TcpServer.foo
=> I listen in IP 1.2.3.5

UdpServer.foo
=> I listen in IP 1.2.3.4


--
Iaki Baz Castillo
<ibc / aliax.net>