Ruby module name from a class defined in
1 answer
You can do this with the Module :: nesting method :
nesting -> array
Returns a list of modules nested within the caller.
module M
class C
Module.nesting[1] # => M
end
end
If you want to get this value from instance methods, you can assign it to a class variable:
module Hello
class Hi
@@parent = Module.nesting[1]
def initialize()
puts @@parent # => Hello
end
end
end
+3
source to share