D
Daniel Berger
Hi all,
Ruby 1.8.x
Is there a way to determine a classes namespace from within an
instance method?
class Foo
def initialize
# print namespace
end
end
Foo.new # 'Object'? 'Kernel'? nil?
module Bar
Foo.new # 'Bar'
end
module Baz
module Bar
Foo.new # 'Baz::Bar'
end
end
If not, is it possible at the class level? I looked at Module#nesting
and Module#name, but I couldn't see how to use those to get what I
want.
Thanks,
Dan
Ruby 1.8.x
Is there a way to determine a classes namespace from within an
instance method?
class Foo
def initialize
# print namespace
end
end
Foo.new # 'Object'? 'Kernel'? nil?
module Bar
Foo.new # 'Bar'
end
module Baz
module Bar
Foo.new # 'Baz::Bar'
end
end
If not, is it possible at the class level? I looked at Module#nesting
and Module#name, but I couldn't see how to use those to get what I
want.
Thanks,
Dan