From: Josh Cheek Date: 2010-11-26T02:54:02+09:00 Subject: Re: VERSION constant issue --001636310389552da00495e44ae8 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Nov 25, 2010 at 7:54 AM, 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? > > 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). > > Here are my results. 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 VERSION # => "1.8.7" self::VERSION # => "1.0.0" def self.method VERSION # => "1.8.7" end method end # going back through ruby versions # I wasn't able to get these to print # the ruby version until 1.7.1 # thanks, ruby-versions.net :) Foo::VERSION # => "1.0.0" Foo::VERSION # => "1.0.0" --001636310389552da00495e44ae8--