Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6055043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:13:13+00:00 2026-05-23T08:13:13+00:00

Is there a quick way to track the methods that are being called on

  • 0

Is there a quick way to track the methods that are being called on an object? Often, when I’m working with a gem at a level just below their public interface, I run into errors that are hard to track down. Ultimately, I end up tracking the object through the source code and keeping everything in my head.

But it would be nice to be able to call something like a #log_method_calls on an object so that, say, all methods called on it get printed to stdout or something. Is there any way to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:13:14+00:00Added an answer on May 23, 2026 at 8:13 am

    There are several methods to do it, depending on the situation.

    If it’ possible to create a new object instead of the observed, you can easily write an observer class using method_missing.

    class LogProxy  
      def initialize obj
        @obj = obj
      end
    
      def method_missing(name, *args)
        puts "#{name} => #{args.to_s}"  
        @desk.send(name, *args)
      end
    end
    

    If it’s not possible, you still may use alias_method. It’s a bit more tricky, but using Module.instance_methods you can chain every method of anything.

    Something like:

    module Logger
    
      def self.included(mod)
        mod.instance_methods.each do |m|
          next if m =~ /with_logging/
          next if m =~ /without_logging/
    
          mod.class_eval do
    
            define_method "#{m}_with_logging" do |*args|
              puts "#{m} called #{args.to_s}"
              self.send_without_logging "#{m}_without_logging", *args
            end
    
            alias_method "#{m}_without_logging", m
            alias_method m, "#{m}_with_logging"
          end
    
        end
      end
    
    end
    
    TargetClass.send(:include, Logger)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there quick way to get the ImageFormat object associated to a particular file
Is there a quick way to detect classes in my application that are never
Is there a quick way or function that would tell me true/false if all
Is there a quick way in java to get the nest/recurse level? I'm writing
Are there any quick way to map some IDataReader to object without third party
Is there a quick way to join paths like the Join-Path function in Powershell?
Is there a quick way to find every match of a regular expression in
is there a quick way to sort the items of a select element? Or
Is there a quick way to set an HTML text input ( <input type=text
Is there a quick way to determine whether you are using certain namespaces in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.