On Thu, Mar 7, 2013 at 12:26 PM, Joel Pearson <lists / ruby-forum.com> wrote: > Can this work for constants as well? I have a several constants within a > long class name and I was wondering whether I can use this approach, but > it doesn't seem to be working for me: > > irb(main):001:0> class A > irb(main):002:1> B = 1 > irb(main):003:1> end > => 1 > irb(main):004:0> A::B > => 1 > irb(main):005:0> A.new.instance_eval do > irb(main):006:1* puts B > irb(main):007:1> end > NameError: uninitialized constant B > from (irb):6:in `block in irb_binding' > from (irb):5:in `instance_eval' > from (irb):5 > from C:/Ruby193/bin/irb:12:in `<main>' Const lookup works differently from other identifiers (IIRC it's done via lexical scope). Having said that you can do irb(main):007:0> A.new.instance_eval { self.class.const_get :B } => 1 Well, probably not what you wanted. :-) How do you want to use that feature (if it existed)? Maybe there's another elegant solution. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/