Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Module#const_added callback #4521

Merged
merged 1 commit into from Jan 14, 2022
Merged

Add a Module#const_added callback #4521

merged 1 commit into from Jan 14, 2022

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented May 22, 2021

Ref: https://bugs.ruby-lang.org/issues/17881

Works similarly to method_added.

This should allow autoloaders like Zeitwerk to forgo usage of TracePoint.

TracePoint works fine, but it's a bit unfortunate that it cause tons of real word application to use an API that is meant for debugging purposes and have performance impact (albeit relatively minor).

Additionally, it would be useful for gems like tapioca to help introspect codebases.

@fxn
Copy link
Contributor

fxn commented May 22, 2021

While the discussion happens in Redmine, what about adding a test about how it behaves with an autoload call?

@casperisfine
Copy link
Contributor Author

what about adding a test about how it behaves with an autoload call?

Yeah good point. I added a test for the current behavior. It is debatable wether that behavior is "correct".

[Feature #17881]

Works similarly to `method_added` but for constants.

```ruby
Foo::BAR = 42 # call Foo.const_added(:FOO)
class Foo::Baz; end # call Foo.const_added(:Baz)
Foo.autoload(:Something, "path") # call Foo.const_added(:Something)
```
@casperisfine
Copy link
Contributor Author

The feature was accepted in the last dev meeting. I updated the NEWS.md and did some minor doc improvements. I'll merge on green CI.

@casperisfine
Copy link
Contributor Author

There's some OpenSSL failure on MinGW which seems unrelated, other than that CI is green.

@byroot byroot merged commit 8d05047 into ruby:master Jan 14, 2022
@fxn
Copy link
Contributor

fxn commented Jan 14, 2022

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants