Skip to content

Instantly share code, notes, and snippets.

@jakenotjacob
Created May 12, 2021 19:35
Show Gist options
  • Save jakenotjacob/d71ddbf2da4c94d6743d2d74d0abe428 to your computer and use it in GitHub Desktop.
Save jakenotjacob/d71ddbf2da4c94d6743d2d74d0abe428 to your computer and use it in GitHub Desktop.
Using Ruby module hooks to inject class methods
module Executor
def self.included(classname)
puts "#{classname} included me, #{self}! I feel loved!"
puts "Now I am going to automagic some methods into #{classname}..."
classname.class_eval do
def scream
"OH MY GLOB"
end
end
end
end
class Thingie
include Executor
end
t = Thingie.new
t.scream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment