#inherited
is called right after the class Foo
statement. I want something that'll run only after the end
statement that closes the class declaration.
Here's some code to exemplify what I need:
class Class
def inherited m
puts "In #inherited for #{m}"
end
end
class Foo
puts "In Foo"
end
puts "I really wanted to have #inherited tiggered here."
### Output:
# In #inherited for Foo
# In Foo
# I really wanted to have #inherited tiggered here.
Does anything like that exist? Can it be created? Am I totally out of luck?
I am late, but I think I have an answer (to anyone who visit here).
You can trace until you find the end of the class definition. I did it in a method which I called
after_inherited
:Output:
Use
TracePoint
to track when your class sends up an:end
event.This module will let you create a
self.finalize
callback in any class.Now you can extend your class and define
self.finalize
, which will run as soon as the class definition ends: