He wants to know the nesting where the Foo object was created not the
nesting of the Foo class itself. i.e. whenever Foo.new is called,
what is the namespace where it was called.
Thanks,
He wants to know the nesting where the Foo object was created not the
nesting of the Foo class itself. i.e. whenever Foo.new is called,
what is the namespace where it was called.
Frankly, I’m stumped.
harp:~ > cat a.rb
require ‘binding_of_caller’
class Foo
def self.new
Binding.of_caller{|b| p eval(‘Module.nesting’, b).shift }
end
end
Foo.new # ‘Object’? ‘Kernel’? nil?
module Bar
Foo.new # ‘Bar’
end
module Baz
module Bar
Foo.new # ‘Baz::Bar’
end
end