Project

General

Profile

Actions

Bug #15780

closed

Module#const_defined?(String) executes autoloads

Added by fxn (Xavier Noria) about 5 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
[ruby-core:92351]

Description

The documentation of Module#const_defined? says that autoloads are not executed:

[...] if the constant is not present but there is an autoload for it, true is returned directly without autoloading.

While this seems to work as documented for symbols, constant names passed as strings trigger the autoload:

$ cat x.rb
p X = 1

$ cat foo.rb
Object.autoload("X", "x")
p Object.const_defined?("X")

$ ruby -I. foo.rb
1
true

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #10741: const_defined? triggers autoload where it did not beforeClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0