TOPLEVEL_OBJECT Constant (#19)

Submitted by: Daniel Brumbaugh Keeney

This revision by: Daniel Brumbaugh Keeney

Date: Wed Mar 26 04:21:16 -0500 2008

ABSTRACT

Ruby is lacking a TOPLEVEL_OBJECT constant, little-used, but useful in certain meta-programming situations, which, by nature, should be in the Ruby core library.

PROBLEM

Ruby lacks a TOPLEVEL_OBJECT constant, which provides access to the object resulting from this Ruby expression:

eval( ‘self’, ::TOPLEVEL_BINDING )

Specifically, a use case where I found the need to assign TOPLEVEL_OBJECT was in a tracing program, where it was helpful to exclude certain objects from being traced. TOPLEVEL_OBJECT needed to be referenced to be added to the list of exclusions.

PROPOSAL

In Ruby core, define Object::TOPLEVEL_OBJECT to be the result of the Ruby expression “eval( ‘self’, ::TOPLEVEL_BINDING )”

ANALYSIS

TOPLEVEL_OBJECT is a built-in object of the Ruby programming language, which should be accessible from any point in Ruby code. It is well-suited to be assigned to a constant. This constant assignment is comparable to TOPLEVEL_BINDING, in that, while any library could trivially assign the value to a constant, it is an object inherent to the Ruby programming language, and therefore should be assigned to a constant by the core library.

IMPLEMENTATION

Effectively described under “Proposal”

Comments


Return to top

Copyright © 2006, Ruby Power and Light, LLC