On 7/5/2011 10:15 AM, Intransition wrote:
>
>       k = Class.new() do
>         class X; end
>       end
>
>      k::X.object_id
>
> results in
>
>      (irb):7: warning: toplevel constant X referenced by #<Class:
> 0x00000001954380>::X
>
[...]
> Is there any way to isolate X to k? And then apply it to the more
> general dynamic case?
>
> Thanks.
>

You can use Module#const_set.

const_set :X, Class.new

Entering the block scope does not automatically change the current 
context for constant definition (the core developers call it the 
`cref'), nor does instance_eval and class_eval.