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

  • Home
  • SEARCH
  • 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 6674371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:44:14+00:00 2026-05-26T03:44:14+00:00

I am using jruby to run bunch of ruby scripts, though I am using

  • 0

I am using jruby to run bunch of ruby scripts, though I am using pure ruby part of it.

It sometimes gets difficult to follow from output what exactly is happening or where exactly something went wrong.

I wanted to get something like this in my std out for every method:
entered in method A
out of method A

Now I can surely go and put those comments in every method ..which feels very wrong. Is there a way to run ruby in a little verbose more to get this information in my log. Hopefully I would avoid using a lot of gems etc .. since these are on some managed servers and I will have to spend some time to just get more s/f on it. Hoping something would be avail as part of jruby itself

Thanks!

  • 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-26T03:44:16+00:00Added an answer on May 26, 2026 at 3:44 am

    You could use this code:

    module InOutHook
      module ClassMethods
        def setup_hooks(*syms)
          syms.each do |sym| # For each symbol
            str_id = "__#{sym}__hooked__"
            unless private_instance_methods.include?(str_id)
              alias_method str_id, sym        # Backup original method
              private str_id                  # Make backup private
              define_method sym do |*args|    # Replace method
                puts ">>> #{self.class}\##{sym} >>>"
                ret = __send__ str_id, *args  # Invoke backup
                puts "<<< #{self.class}\##{sym} >>>"
                ret
              end
            end
          end
        end
      end
      def InOutHook.included(base)
        base.extend(ClassMethods)
      end
    end
    
    class TestClass
      def test1
        puts "test!"
      end
      def test2(v)
        puts "Value is #{v}"
      end
      include InOutHook
      setup_hooks(:test1, :test2)
    end
    
    # works on existing classes too:
    class Array
      include InOutHook
      setup_hooks(:[])
    end
    
    tc = TestClass.new
    tc.test1
    tc.test2(10)
    
    ary = [1,2,3]
    puts ary[1..2]
    

    In case you want to add a hoot to every method, just add a splat asterisk:

    setup_hooks(*[].methods)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ruby script which I run using the JRuby Interpreter. The script
I'm trying to run a rails 3 app on a windows server using jruby
I'm trying to run a rails 3 app on a windows server using jruby
I have an app that I am migrating from Ruby to JRuby (due to
Im using Jruby (thats ruby anyway, running under jvm :D ) with marathon test
Been trying to run a rails app using terminal in jruby 1.9 mode. I
I am using Jruby and rails 2.2.2. My problem is I have a migration
Has anyone seen this: ?? No jgem command works at all?? Though jruby -S
Are there specific frameworks for Jython or JRuby, or is it you can run
I've spent the last 9 months using Ruby on Rails exclusively. I've been asked

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.