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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:13:22+00:00 2026-06-14T04:13:22+00:00

I want to watch the flow the execution of my ruby code when I

  • 0

I want to watch the flow the execution of my ruby code when I am in the console. For example, if I have this :

def process
  hash = {a:1,b:2}
  hash.values.map!{|e| e+1}
end

And I want to see something like this in console when I type process :

hash = {a:1,b:2}
=> {:a=>1, :b=>2}
hash.values.map!{|e| e+1}
=> [2, 3]

Is there a useful way to do something like this?

$VERBOSE doesn’t seems to do anything and $DEBUG seems as the opposite to be too verbose.

  • 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-06-14T04:13:23+00:00Added an answer on June 14, 2026 at 4:13 am

    You’re talking about “trace” functionality.

    Some languages, like shell and good-ol’ GWBasic, have a flag to show their currently executing line. Ruby’s $DEBUG output can flood you with information overload, not so much from your code, but from any gems that look for it and dump their current state or turn on their tracing.

    Many people sprinkle their code with puts to have it show some indicator of where they are, during their development/testing. If you do that, I’d recommend writing it as a method to bottleneck your output and let you easily turn it on/off. Also, use a flag to check whether you want to debug. You might even want to use OptionParser to let you create a --debug flag to pass on the command-line. Another nice side-effect of using a method is it’s easy to redirect the output to a file you can tail and watch the output as it occurs, and later use for triage.

    Another alternative is to load the code into the debugger and tell it to trace. You’ll see every step of the code, which is very verbose, but the detail is good. You can also tell it to run to certain points so you can poke at the code and dig around, dropping into IRB if needed.

    Personally, being old-school and having cut my teeth on assembly-language, I’m comfortable in debuggers, so I use Ruby’s a lot. It’s easy to tell it to run to a certain spot and stop, or you can embed include 'debugger'; debugger into your code and it’ll stop at that point. Once there, it’s possible to see what’s going on, then c to continue, and let the program run until it hits the debugger statement again. I find the debugger to be very powerful and a nice selective magnifying glass for those times I want to know what’s going on.

    “Debugging in Ruby” has lots of nice tips you might find useful too.


    EDIT:

    I like Alex D’s suggestion to look into Ruby’s set_trace_func. I haven’t used it (and, frankly forgot about it), but that’d be a good way to set up a nice trace in an app. With a little code you could set up toggling it on/off and selectively outputting given a certain class or condition since you’re in control of the proc being called.

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

Sidebar

Related Questions

I want this url http://www.youtube.com/watch?v=dgNgODPIO0w&feature=rec-HM-fresh+div to be transformed to: http://www.youtube.com/v/dgNgODPIO0w with php.
i want to play the video of this URL http://www.youtube.com/watch?v=JPUWNcGDyvM&feature=player_embedded where i PAUSE last
is there a way to do line-bufferd cat? For example, I want to watch
I have a knockout viewModel with an array of items. I want to watch
i want to create something like this http://www.youtube.com/watch?v=UJ7E7uEZN00&feature=player_embedded can i create a composition and
In my iPhone OS application I want (need) to watch for changes in the
I just want to show more than one Watch window. There, they say that
Is there a way to create a simple guard watch? I want to run
I'm stuck with a code. I want to see witch events from a MySQL
I want to watch a system setting and get notified when its value changes.

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.