From: shevegen@... Date: 2017-12-02T21:42:16+00:00 Subject: [ruby-core:84061] [Ruby trunk Bug#14148] Longstanding behavior regarding correspondence of toplevel with Object is surprising Issue #14148 has been updated by shevegen (Robert A. Heiler). > should be something like toplevel::X I think that one problem here is that a new method? Or keyword, aka "toplevel", would be added in the case that you showed. I guess it would be nice if ruby could clearly document what toplevel is and make this available somewhere, be it part of the official docs or the ruby wiki here. I remember having had read on the old pickaxe that the methods on "toplevel" become private methods of class Object, so perhaps this may explain some of the behaviour. But either way, I think it is best to describe the whole toplevel situation rathern than have to rely on blog entries (not that blog entries are bad, mind you; I just think that the documentation of ruby should ideally be kept within official ruby). Search for toplevel yields some weird results by the way. :D First, some blogs are found, and then RDoc: https://ruby-doc.org/stdlib-2.2.1/libdoc/rdoc/rdoc/RDoc/TopLevel.html Pretty hilarious to me. :D > But I don't think I have the level of understanding to make a > concrete proposal that would preserve some level of compatibility > while meeting the expectations of both new and longtime rubyists. I would not either, but I think either way, it should be documented somewhere. I mean, to me it is not a huge result in the sense that after reading the old pickaxe on "def foo" on toplevel becoming a part of class Object, so it's really not something that confuses me personally. But perhaps newcomers may be confused, and here it would be helpful if they could read up on some of the situation of toplevel. ---------------------------------------- Bug #14148: Longstanding behavior regarding correspondence of toplevel with Object is surprising https://bugs.ruby-lang.org/issues/14148#change-68148 * Author: RickHull (Rick Hull) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- ~~~ ruby module Kernel X = 1 end puts String::X X = 2 puts String::X ~~~ ~~~ $ ruby test.rb 1 Traceback (most recent call last): test.rb:9:in `
': uninitialized constant String::X (NameError) Did you mean? X $ ruby --version ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux] ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: