From: Intransition Date: 2010-12-14T06:33:56+09:00 Subject: Re: VERSION constant issue On Dec 13, 1:21 pm, Eric Hodel wrote: > On Nov 25, 2010, at 05:54, Intransition wrote: > > > Ruby's VERSION constant is getting in the way of using #const_missing > > in my module. Here's some example code: > > >  module Foo > >    def self.const_data > >      @const_data ||= { 'version' => '1.0.0' } > >    end > > >    def self.const_missing(name) > >      key = name.to_s.downcase > >      const_data[key] || super(name) > >    end > >  end > > >  Foo::VERSION  #=> '1.8.7' > > > How can I fix this? > > What would ::const_data provide that Module#constants, Module#const_get and Module#const_set and direct constant access don't provide?  If it's something legitimate, invert ::const_data to reference real constants via introspection and get rid of const_missing. I could, but I wanted to lazy load the information b/c it is being read from a file, and in most usecases will not be used. The reason I am using constants is simply b/c it's customary in this case as the information is project metadata, such as VERSION. > > I tried `remove_const(:VERSION)` at the toplevel but discovered that > > some Ruby library don't like that (sorry, can't recall which it was > > off hand). > > File a bug, they should be using RUBY_VERSION. Will do. I tracked it down to a Ruby 1.8.7: e2mmap.rb:fail "Use Ruby 1.1" if VERSION < "1.1"