DEV Community

Discussion on: Decorating Ruby - Part Two - Method Added Decoration

Collapse
 
edisonywh profile image
Edison Yap • Edited

Wow this is really cool, thanks for sharing Brandon!

Is there a way to hook onto the last method_added? For example I'd like to execute something after all methods are added

EDIT: also quick search online seems to say that method_added only works for instance methods, but there's singleton_method_added hook for class methods too!

Collapse
 
baweaver profile image
Brandon Weaver • Edited

Technically in Ruby there's never a point in which methods are no longer added, so it's a bit hard to hook that. One potential is to use TracePoint to hook the ending of a class definition and retaining a class of "infected" classes, but that'd be slow.

Look for "Class End Event" in this article: medium.com/@baweaver/exploring-tra...

EDIT - ...though now I'm curious if one could use such things to freeze a class from modifications.