# Add debug to help info

**URL:** <https://rubytalk.org/t/add-debug-to-help-info/7010>\
**Category:** ruby-talk\
**Created:** [25 July 2003 08:57 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010 "2003-07-25T08:57:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Cowham](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@Robert\_Cowham](https://rubytalk.org/u/Robert_Cowham)\
**Post date:** [25 July 2003 08:57 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/1 "2003-07-25T08:57:49Z")

</div>

Is it just me or is how to debug a ruby script unnecessarily hidden?

Can I suggest adding to the output of ruby -h something to indicate how  
to debug.

With 1.68:

C:\>ruby -h  
Usage: ruby [switches] [–] [programfile] [arguments]  
-0[octal] specify record separator (\0, if no argument)  
-a autosplit mode with -n or -p (splits $\_ into $F)  
-c check syntax only  
-Cdirectory cd to directory, before executing your script  
-d set debugging flags (set $DEBUG to true)  
-e ‘command’ one line of script. Several -e’s allowed. Omit  
[programfile]  
-Fpattern split() pattern for autosplit (-a)  
-i[extension] edit ARGV files in place (make backup if extension  
supplied)  
-Idirectory specify $LOAD\_PATH directory (may be used more than  
once)  
-Kkcode specifies KANJI (Japanese) code-set  
-l enable line ending processing  
-n assume ‘while gets(); … end’ loop around your script  
-p assume loop like -n but print line also like sed  
-rlibrary require the library, before executing your script  
-s enable some switch parsing for switches after script  
name  
-S look for the script using PATH environment variable  
-T[level] turn on tainting checks  
-v print version number, then turn on verbose mode  
-w turn warnings on for your script  
-x[directory] strip off text before #!ruby line and perhaps cd to  
directory  
–copyright print the copyright  
–version print the version

First off, I was confused by the -d option. It seemed to have no effect.  
It then took some searching around to find out that “ruby -rdebug” was  
what I needed.

Perhaps the output could be modified to:

-d set debugging flags (set $DEBUG to true)  
Note to debug your script use “-rdebug”

Just out of curiosity, what does setting the $DEBUG flag do??

> **···**
>
> –  
> Robert Cowham

---

<div class="post-metadata">

**Author:** ![Tim\_Kynerd2](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Tim\_Kynerd2](https://rubytalk.org/u/Tim_Kynerd2)\
**Post date:** [25 July 2003 09:38 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/2 "2003-07-25T09:38:13Z")

</div>

I’d like to second this. I was trying to debug something last night, and I  
had to open up the pickaxe book to see how to actually start the debugger.

I would also be interested to know what the $DEBUG flag does.

> **···**
>
> On Fri, 25 Jul 2003 08:43:44 +0000, Robert Cowham wrote:
> 
> > Is it just me or is how to debug a ruby script unnecessarily hidden?
> > 
> > Can I suggest adding to the output of ruby -h something to indicate how to  
> > debug.
> > 
> > With 1.68:
> > 
> > C:\>ruby -h  
> > Usage: ruby [switches] [–] [programfile] [arguments]  
> > -0[octal] specify record separator (\0, if no argument) -a  
> > autosplit mode with -n or -p (splits $\_ into $F) -c  
> > check syntax only  
> > -Cdirectory cd to directory, before executing your script -d  
> > set debugging flags (set $DEBUG to true) -e ‘command’ one line  
> > of script. Several -e’s allowed. Omit  
> > [programfile]  
> > -Fpattern split() pattern for autosplit (-a) -i[extension] edit  
> > ARGV files in place (make backup if extension  
> > supplied)  
> > -Idirectory specify $LOAD\_PATH directory (may be used more than  
> > once)  
> > -Kkcode specifies KANJI (Japanese) code-set -l  
> > enable line ending processing -n assume ‘while gets(); …  
> > end’ loop around your script -p assume loop like -n but  
> > print line also like sed -rlibrary require the library, before  
> > executing your script -s enable some switch parsing for  
> > switches after script  
> > name  
> > -S look for the script using PATH environment variable  
> > -T[level] turn on tainting checks -v print version  
> > number, then turn on verbose mode -w turn warnings on for  
> > your script -x[directory] strip off text before #!ruby line and  
> > perhaps cd to  
> > directory  
> > –copyright print the copyright  
> > –version print the version
> > 
> > First off, I was confused by the -d option. It seemed to have no effect.  
> > It then took some searching around to find out that “ruby -rdebug” was  
> > what I needed.
> > 
> > Perhaps the output could be modified to:
> > 
> > -d set debugging flags (set $DEBUG to true)  
> > Note to debug your script use “-rdebug”
> > 
> > Just out of curiosity, what does setting the $DEBUG flag do??
> 
> –  
> Tim Kynerd Sundbyberg (småstan i storstan), Sweden [tkynerd@spamcop.net](mailto:tkynerd@spamcop.net)  
> Sunrise in Stockholm today: 4:20  
> Sunset in Stockholm today: 21:27  
> My rail transit photos at [http://www.kynerd.nu](http://www.kynerd.nu)

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [25 July 2003 09:50 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/3 "2003-07-25T09:50:32Z")

</div>

Hi,

> I would also be interested to know what the $DEBUG flag does.

It changes two behaviors.

Reports exceptions at raised.

$ ruby -e ‘raise rescue p $!’  
RuntimeError

$ ruby -d -e ‘raise rescue p $!’  
Exception `RuntimeError’ at -e:1 -  
RuntimeError

Exits main thread when any thread aborted by exceptions.

$ ruby -e ‘Thread.new{raise};sleep 1’  
$ ruby -d -e ‘Thread.new{raise};sleep 1’  
Exception `RuntimeError' at -e:1 - -e:1: unhandled exception from -e:1:in `initialize’  
from -e:1:in `new’  
from -e:1

> **···**
>
> At Fri, 25 Jul 2003 18:38:13 +0900, Tim Kynerd wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Ben\_Giddings](https://rubytalk.org/u/Ben_Giddings)\
**Post date:** [25 July 2003 17:18 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/4 "2003-07-25T17:18:01Z")

</div>

While we’re on the subject, I hunted around in /usr/lib/ruby/1.6 and found:

tk.rb: p ‘create\_self has no arg’ if $DEBUG  
tempfile.rb: print “done\n” if $DEBUG  
tcltk.rb: print(“mainloop: start\n”) if $DEBUG  
cgi.rb: $stderr.printf(“name:%s value:%s\n”, name, value) if $DEBUG

and:

jcode.rb: printf STDERR, “feel free for some warnings:\n” if $VERBOSE  
net/http.rb: $stderr.puts “WARNING: duplicated HTTP header: #{k}” if  
$VERBOSE  
net/http.rb: $stderr.puts ‘Content-Type did not set; using  
application/x-www-form-urlencoded’ if $VERBOSE

For my own code, I’ve wrapped debug prints to save keystrokes. Do other  
people do this, or do you all just append “if $DEBUG” or “if $VERBOSE” to the  
end of your statements?

Is there any interest in a standard Ruby module that does debug prints, debug  
block runs, and other standard debugging things? Does anybody already have  
their own that they’d like to share?

I like Log4r and use it, but sometimes I’d like something a little simpler and  
more lightweight.

Ben

> **···**
>
> On Fri July 25 2003 5:38 am, Tim Kynerd wrote:
> 
> > I would also be interested to know what the $DEBUG flag does.

---

<div class="post-metadata">

**Author:** ![Robert\_Cowham](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@Robert\_Cowham](https://rubytalk.org/u/Robert_Cowham)\
**Post date:** [25 July 2003 23:23 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/5 "2003-07-25T23:23:10Z")

</div>

[nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote in news:200307250950.h6P9oUxL026371  
@sharui.nakada.kanuma.tochigi.jp:

> Hi,
> 
> > I would also be interested to know what the $DEBUG flag does.
> 
> It changes two behaviors.
> 
> Reports exceptions at raised.
> 
> $ ruby -e ‘raise rescue p $!’  
> RuntimeError
> 
> $ ruby -d -e ‘raise rescue p $!’  
> Exception `RuntimeError’ at -e:1 -  
> RuntimeError
> 
> Exits main thread when any thread aborted by exceptions.
> 
> $ ruby -e ‘Thread.new{raise};sleep 1’  
> $ ruby -d -e ‘Thread.new{raise};sleep 1’  
> Exception `RuntimeError' at -e:1 - -e:1: unhandled exception from -e:1:in `initialize’  
> from -e:1:in `new’  
> from -e:1

That’s interesting.

Given the compatibility of Ruby with various Perl flags (-ane for  
example), -d for debug seems more important to me than the above  
behaviour (for the average person…).

Just a thought (and would correspond to least surprise principle too!!)

> **···**
>
> > At Fri, 25 Jul 2003 18:38:13 +0900, \> Tim Kynerd wrote:
> 
> –  
> Robert Cowham

---

<div class="post-metadata">

**Author:** ![Zachary\_P\_Landau](https://avatars.discourse-cdn.com/v4/letter/z/e99b99/32.png) [@Zachary\_P\_Landau](https://rubytalk.org/u/Zachary_P_Landau)\
**Post date:** [30 July 2003 02:20 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/6 "2003-07-30T02:20:20Z")

</div>

> Is there any interest in a standard Ruby module that does debug prints, debug  
> block runs, and other standard debugging things? Does anybody already have  
> their own that they’d like to share?
> 
> I like Log4r and use it, but sometimes I’d like something a little simpler and  
> more lightweight.

I think this would be absolutely great to have included. A nice,  
quick, standard way to print out different debugging levels. I’d say  
keep it similar to log4r. Have info() warn() etc that print out  
depending on the debugging level set. It might be nice to not need to  
create an object for it thought. Rather than create a global $debug =  
Debug.new, it might be nicer to just be able to call Debug.info(‘hey,  
i’m a debugging statement’). You shouldn’t ever need more than one  
debugging instance at once anyway.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [27 July 2003 13:55 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/7 "2003-07-27T13:55:17Z")

</div>

Hi,

> **···**
>
> At Sat, 26 Jul 2003 08:23:10 +0900, Robert Cowham wrote:
> 
> > Given the compatibility of Ruby with various Perl flags (-ane for  
> > example), -d for debug seems more important to me than the above  
> > behaviour (for the average person…).
> 
> I have no particular idea about this. NaHi may do something.
> 
> One I thought, this -D option would be nice.
> 
> -D[number/list] set debugging flags (argument is a bit mask or alphabets)
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![NAKAMURA\_Hiroshi1](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@NAKAMURA\_Hiroshi1](https://rubytalk.org/u/NAKAMURA_Hiroshi1)\
**Post date:** [30 July 2003 03:23 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/8 "2003-07-30T03:23:23Z")

</div>

Hi,

> From: “Zachary P. Landau” [kapheine@hypa.net](mailto:kapheine@hypa.net)  
> Sent: Wednesday, July 30, 2003 11:20 AM

> > Is there any interest in a standard Ruby module that does debug prints, debug  
> > block runs, and other standard debugging things? Does anybody already have  
> > their own that they’d like to share?
> > 
> > I like Log4r and use it, but sometimes I’d like something a little simpler and  
> > more lightweight.

I use [RAA:devel-logger]. (disclaimer from its author)

> I think this would be absolutely great to have included. A nice,  
> quick, standard way to print out different debugging levels. I’d say  
> keep it similar to log4r. Have info() warn() etc that print out  
> depending on the debugging level set.

Agreed.

// NaHi

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [30 July 2003 02:09 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/9 "2003-07-30T02:09:34Z")

</div>

sligthly related: I’ve been thinking if could be possibe a  
-v\<warn\_level|warning\_class\*\> that would set $VERBOSE to something  
(i.e an hash ) instead of plain true.  
This won’t even break code with checks like  
if $VERBOSE.

This way, for example , one could still look for unreachable  
statements but forget uninitialized variables, or enable warnings for  
changes beetween 1.6 and 1.8, or ‘for future version’ warnings…

or possibly this already happens ?

> **···**
>
> il Sun, 27 Jul 2003 22:55:17 +0900, [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) ha scritto::
> 
> > Hi,
> > 
> > At Sat, 26 Jul 2003 08:23:10 +0900, \>Robert Cowham wrote:
> > 
> > > Given the compatibility of Ruby with various Perl flags (-ane for  
> > > example), -d for debug seems more important to me than the above  
> > > behaviour (for the average person…).
> > 
> > I have no particular idea about this. NaHi may do something.
> > 
> > One I thought, this -D option would be nice.
> > 
> > -D[number/list] set debugging flags (argument is a bit mask or alphabets)

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [30 July 2003 02:09 UTC](https://rubytalk.org/t/add-debug-to-help-info/7010/10 "2003-07-30T02:09:37Z")

</div>

I meant -w not -v, sorry

> **···**
>
> il Sun, 27 Jul 2003 15:26:58 GMT, gabriele renzi [surrender\_it@remove.yahoo.it](mailto:surrender_it@remove.yahoo.it) ha scritto::
