Skip to content

Instantly share code, notes, and snippets.

@jdwolk
Last active June 3, 2020 19:21
Show Gist options
  • Save jdwolk/4e33204b232168bc9b64bc1fb769e0ce to your computer and use it in GitHub Desktop.
Save jdwolk/4e33204b232168bc9b64bc1fb769e0ce to your computer and use it in GitHub Desktop.
Ruby superclass/subclass AOP
module LogOnCall
def call
puts "Logging #{self.class.name}.call"
super
end
end
class BaseThing
### MAGIC HAPPENS HERE
def self.inherited(subclass)
subclass.prepend LogOnCall
end
###
end
class Thing < BaseThing
def call
puts "Heyo!!!"
end
end
# pry(main)> Thing.new.call
# Logging Thing.call
# Heyo!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment