From: "bughit (bug hit) via ruby-core" <ruby-core@...> Date: 2023-05-24T01:44:02+00:00 Subject: [ruby-core:113607] [Ruby master Feature#19644] Module::current to complement Module::nesting Issue #19644 has been updated by bughit (bug hit). nobu (Nobuyoshi Nakada) wrote in #note-10: > bughit (bug hit) wrote in #note-8: > > `Module.nesting(n)` does address the perf aspect, but it makes rather it too verbose and obfuscated/ugly to get the current: `Module.nesting(1)[0]`. > > I thought it would be `Module.nesting(0)`, or `Module.nesting(0..)[0]`. Module::nesting(index_or_range) returning a module for an index, looks like an easy enhancement of the existing method. It should probably be done regardless, it's just better API design. Still, a single label identifier (like `__mod(ule)__`) looks better: `"#{__module__}##{__method__}"` I already mentioned one use-case, logging/tracing. Basically any kind of generic code that you might place in multiple methods in multiple classes, that needs to refer to the current class/module. ---------------------------------------- Feature #19644: Module::current to complement Module::nesting https://bugs.ruby-lang.org/issues/19644#change-103250 * Author: bughit (bug hit) * Status: Rejected * Priority: Normal ---------------------------------------- Module::current == Module::nesting[0] but without needlessly walking the entire nesting hierarchy. Could be useful for debugging/logging. It could also be a Kernel global (like `__method__`) or a keyword (like `__FILE__`) -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/