Hello! As far as I know, there is no way to reference the current Class or Module one is inside of lexically in Ruby. Would it make sense to add a syntax/keyword for this?
moduleFoomoduleBardefblahputs"executing from #{magic_new_keyword}"endendendclassBazincludeFoo::Bardefblahsuperputs"executing from #{self.class.name}"endendBaz.new.blah
I think you should be able to use Module.nesting.first to get the closest lexical nesting to the executing code. There might be edge-cases where this doesn't work the way you might want it to work, but it definitely works for your example:
moduleFoomoduleBardefblahputs"executing from #{Module.nesting.first}"endendendclassBazincludeFoo::Bardefblahsuperputs"executing from #{self.class.name}"endendBaz.new.blah
I think you should be able to use Module.nesting.first to get the closest lexical nesting to the executing code. There might be edge-cases where this doesn't work the way you might want it to work, but it definitely works for your example:
moduleFoomoduleBardefblahputs"executing from #{Module.nesting.first}"endendendclassBazincludeFoo::Bardefblahsuperputs"executing from #{self.class.name}"endendBaz.new.blah
outputs
executing from Foo::Bar
executing from Baz
It absolutely does--apologies for using up your time informing me of an existing API! Thank you!