From: Trans Date: 2008-10-20T11:41:12+09:00 Subject: Re: Proc metaprogramming tricks? On Oct 19, 5:18 pm, Adam Skobi wrote: > >> I'm building a DSL and trying some weird syntax structures. My DSL > >> should look like this. > >     def dsl(&block) > >       C.module_eval(&block) > >     end > > Well yeah, that would work. But I was thinking about something more > general. > > class Root >   def dsl(&block) >     instance_eval(&block) >   end > end > > class C >   #... > end > > class D >   #... > end > > dsl { >   met1 > >   class C1 < C >     #... >   end > >   class D1 < D >     #... >   end > > } > > Can I run part of the Proc in the context of C and part in the > context of D i.e. can I somehow split the Proc or convert it to a > readable String? > > The more I think about it, the more absurd the reasoning behind it > seems. But since I'm at it, I may as well continue the debate :-) You can just allow them to be defined in Root and then use #inherited to set C::C1 = Root:C1 D::D1 = Root:D1 ... (using const_get and const_set) T.