From: Intransition Date: 2011-07-05T23:15:31+09:00 Subject: Define a constant in dynamically defined class Have me a conundrum. k = Class.new() do class X; end end k::X.object_id results in (irb):7: warning: toplevel constant X referenced by #::X I don't want X to be toplevel. I want it to be under `k`. To complicate matters I don't have control over the block, as it actually comes from a testing procedure defined by an end user. The actual code is this: # Create a sub-case. # def context(desc=nil, &block) cls = Class.new(TestCase, &block) cls.desc(desc) if desc cls end Is there any way to isolate X to k? And then apply it to the more general dynamic case? Thanks.