From: Caleb Clausen Date: 2010-03-04T07:50:23+09:00 Subject: Re: Class vs Module in constant lookup On 3/3/10, Peter McLain wrote: > Well, the code isn't mine, but I'd still like to understand if > there is a rationale for the difference in behavior, or if this is > just another MRI implementation detail that's leaked out. Currently, > MagLev returns "constant" for both classes and modules, but that > breaks third party code. E.g,: > > return unless defined? RDoc::VERSION # RDoc 1 does not have VERSION > # code that blows up if RDoc 1 being used... > > One could argue that the proper test, which works for both classes and > modules in all ruby implementations, is: > > return unless RDoc.const_defined? :VERSION > > But I'd still like to understand if the difference in behavior is > intended or an implementation quirk, and if it is intended, what the > rationale is. Ok, I see your problem, and I sympathize. Collisions of the toplevel constant VERSION with VERSIONs defined inside classes are a repeated snafu. (It's bitten me.) This is probably why MRI 1.9 no longer defines VERSION, but RUBY_VERSION instead. I'd suspect this is unintended, but for an authoritative answer you'll have to get matz or another core maintainer to chime in. You might ask on ruby-core; I suspect those guys don't pay a lot of attention to this list nowadays.