Project

General

Profile

Actions

Bug #7695

closed

Constant Lookup - For goodness sake it should at least see itself!

Added by trans (Thomas Sawyer) over 11 years ago. Updated almost 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
[ruby-core:51429]

Description

=begin
Example:

module Foo; end
module Foo::Bar
p Bar
end
NameError: uninitialized constant Foo::Bar::Bar
from (irb):3:in <module:Bar>' from (irb):2 from /opt/Ruby/1.9.3-p327/bin/irb:12:in '

While I understand the technical details of constant lookup and why this happens, it just seems plan wrong on the face of it. Why wouldn't a module/class not at least see ((itself))!?

For use case -- I was writing some code and I determined that a whole set of classes should be under a secondary namespace. It was convenient to go from module Realms to class Realms::Library, but alas, it broke the code, because none of the code inside could see Library anymore. So I had to go through all the files, use two lines instead on one, i.e. module Realms then class Library, indent every line another tab and finally add another end at the bottom of each file. A pain in the arse!

While it might not technically be a "bug", I am going to go ahead and file it as one b/c to me it really seems like one. And if I didn't know exactly how constant lookup worked I would think it one too.
=end

Updated by alexeymuranov (Alexey Muranov) over 11 years ago

Just to link to an older discussion: #6810.

Updated by ko1 (Koichi Sasada) about 11 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)
Actions #3

Updated by naruse (Yui NARUSE) over 6 years ago

  • Target version deleted (2.6)
Actions #4

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0