From: "Eregon (Benoit Daloze) via ruby-core" Date: 2025-04-26T18:25:11+00:00 Subject: [ruby-core:121738] [Ruby Bug#21272] Class.new doesn't trigger :class TracePoint Issue #21272 has been updated by Eregon (Benoit Daloze). In my view, `Baz = Class.new` doesn't really "Start a class or module definition." it creates a class but there is no definition of it, no body. Though `Baz = Class.new { ... }` would arguably start a definition/body, but then so would `Baz.class_exec { ... }` and that seems less reasonable to catch with a :class TracePoint. I think unless there is a good motivating example to change behavior (which could be incompatible), it's better to just document it better, so I'd suggest opening a PR to document it better. ---------------------------------------- Bug #21272: Class.new doesn't trigger :class TracePoint https://bugs.ruby-lang.org/issues/21272#change-112793 * Author: st0012 (Stan Lo) * Status: Open * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- According to the official [documentation](https://docs.ruby-lang.org/en/master/TracePoint.html#class-TracePoint-label-Events): > To filter what is traced, you can pass any of the following as events: > > :class > Start a class or module definition. I'd expect `:class` events to be triggered when new classes are defined via `Class.new` as well, but currently that's not the case. Should we either support `Class.new`, or clarify the behaviour in documentation? ### Reproduction ```rb TracePoint.trace(:class) do |tp| puts "Class created at line: #{tp.lineno}" end class Foo; end # Triggers the tracepoint Baz = Class.new # Doesn't trigger the tracepoint # ruby test.rb # Class created at line: 5 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/