Project

General

Profile

Actions

Feature #19775

closed

Use the callback `main::const_added`

Added by UlyssesZhan (Ulysses Zhan) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:114238]

Description

In #17881, it was accepted that Module#const_added is called when there is a new constant added to the namespace of the module.
Since main can also serve as a namespace, it should also be able to use this callback.

def const_added name
  p name
end
Foo = 1 # => :Foo

Updated by mame (Yusuke Endoh) over 1 year ago

  • Status changed from Open to Closed

Since top-level constants are defined under Object, their definition can be hooked by defining Object.const_added.

def Object.const_added(name)
  p name
end

Foo = 1 #=> :Foo
Actions

Also available in: Atom PDF

Like0
Like0