Reputation: 723
I have simple code
module Foo
def foo
p self
#p 'Foo' -> bad decision for me
end
end
class Bar
include Foo
end
Bar.new.foo #=> #<Bar:0x00000002f0faf8>
But I need something like this
Bar.new.foo #=> Foo
I need the name of the module from which this method was called. So, what are the ways to find out the name of the module
Upvotes: 3
Views: 52
Reputation: 118261
Do as below :
module Foo
def foo
method(__method__).owner
end
end
class Bar
include Foo
end
Bar.new.foo # => Foo
Upvotes: 8