From: Robert Klemme Date: 2008-12-30T03:16:37+09:00 Subject: Re: Include constants from one scope into another ( A::* ) 2008/12/29 Alexey Petrushin : > Hello! Is there a way to include constants from one class into another? > Something like "include A::*"? > > SAMPLE: > > class A > class B; end > class C; end > class D; end > end > > class E > # include A::* > B; C; D; > end robert@fussel ~ $ ruby < > class A > class B; end > class C; end > class D; end > end > > class E > B=::A::B > C=::A::C > D=::A::D > end > p E::C.new > EOF # robert@fussel ~ $ You can as well do something like this class Module def import_all(mod) mod.constants.each do |c| const_set(c, mod.const_get(c)) end end end irb(main):016:0> class E irb(main):017:1> import_all A irb(main):018:1> end => ["C", "B", "D"] irb(main):019:0> E::B.new => # Kind regards robert -- remember.guy do |as, often| as.you_can - without end