Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save styx/2849355 to your computer and use it in GitHub Desktop.
Save styx/2849355 to your computer and use it in GitHub Desktop.
adding introspection to all ActiveRecord methods (putting method's name when it's invoked)
module ActiveRecord
Base.singleton_methods.each do |m|
Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
end
alias_method :"#{m}_without_introspection", :"#{m}"
alias_method :"#{m}", :"#{m}_with_introspection"
end
EOS
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment