On Feb 11, 2007, at 7:02 PM, Victor Zverok Shepelev wrote:

> module Constants
>   TEST = 5
> end
>
> class A
> end
>
> a = A.new
>
> a.instance_eval{
>   extend Constants
>   p TEST #<== here
> }

The only solutions I can think of involve explicitly referencing the  
class:

class Object
   def singleton_class
     (class <<self; self; end)
   end
end

a.instance_eval {
   extend Constants
   singleton_class::TEST
}

But at that point it is probably easier to simply reference Constants
directly:

a.instance_eval {
   t = Constants::TEST
}

It does seem a bit strange to be adding constants to the singleton  
class.
Why not add them to A itself?  That way you don't need to extend the
singleton class with the Constants module.

class A
   include Constants
end

A.new.instance_eval {
   p self.class::TEST    # still a bit ugly...
}


Gary Wright