I wrote a Ruby file my.rb, which has a module definition:
module MyModule
...
end
Another Ruby script requires my.rb on the fly, and I want to dynamically get the module name defined in my.rb. Is it possible?
I wrote a Ruby file my.rb, which has a module definition:
module MyModule
...
end
Another Ruby script requires my.rb on the fly, and I want to dynamically get the module name defined in my.rb. Is it possible?
You can use TracePoint to do that:
# :class is the start of a class or module definition
TracePoint.new(:class) do |trace|
puts "defined a class or module named: #{trace.self}"
end.enable do
require './my'
end
when running this script it will output:
defined a class or module named: MyModule
and only classes that get defined within the enable block get output