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 7399393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:03:18+00:00 2026-05-29T04:03:18+00:00

For a Rails app, I would like to overload or modify Kernel::load such that

  • 0

For a Rails app, I would like to overload or modify Kernel::load such that it will print out the full path like puts "-> #{File.expand_path(File.dirname(__FILE__))}/#{File.basename(__FILE__)}" for each Rails app file that is loaded.

How would I do this? I would like to further be able to filter, so I am guessing I’d throw a regex on there to be able to only show output (when I don’t want it to be grossly verbose) that indicates the access of files within the current rails app root.

At any rate, I’d appreciate an example of overloading this method and where the appropriate place to do this would be active in the Rails app on server start.

Resolution:

Well okay after a bit of beating things around and discovering set_trace_func I came up with the following:

I integrated set_trace_fun into the header of development.rb along the lines of what was implemented in the mtrace gem. I had a lot of tweaking to do to filter out everything but my app directory as well as a number of other chatty methods, but it seems to be working out thus far. The mtrace source that is effectively integrated with modification is as follows:

mtrace_indent = 0
set_trace_func lambda {|event, file, line, id, binding, klass|
  case event
  when 'call'
    puts "\e[90m| " * mtrace_indent +
      "\e[35m#{klass}\e[90m#\e[36m#{id} \e[90m#{file}:#{line}\e[0m" +
      "#{'  ' * ([10 - mtrace_indent, 1].max)}\e[90mtxmt://open/?url=file://#{ File.expand_path(file) }&line=#{ line }\e[0m"
    mtrace_indent += 1
  when 'return'
    mtrace_indent -= 1
  end
  mtrace_indent = 0 if mtrace_indent < 0
}

Of course the txmt url portions can be removed if you’re not on a mac, but that is really quite helpful.

  • 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-29T04:03:19+00:00Added an answer on May 29, 2026 at 4:03 am

    Try this:

    module Kernel
      alias_method :old_load, :load
    
      def load filename, wrap = false
        puts "-> #{filename}"
        old_load filename, wrap
      end
    end
    

    You can put this into config/initializers, but that may be a little bit late for what you’re trying to do.

    Apparently, Rails init process starts with config/environment.rb, so if you put this code at the top of that file, it should be the first thing loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app that uses activescaffold and I would like to hide
I have a Rails 3 app that I would like to tweet certain status
I have a fairly standard rails app and would like to be able to
I would like to add authentication to my Rails app. I came across few
I would like to allow users to call my ruby on rails app as
I'm using Authlogic with my Ruby on Rails App. I would like user to
I would like to performance testing a Rails app. The real world data is
I am creating a small rails app for personal use and would like to
I would like to set a before filter in a rails app as follows:
I am developing in Rails an app where I would like to rank a

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.