Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$DEBUG global variable in Ruby

Tags:

ruby

Can someone please summarize what/when is $DEBUG used. I am unfamiliar with it, and had no luck finding documentation (the Class Thread documentation and Module Signal documentation).

These are examples that are not clear to me what's going on:

p @ivar if $DEBUG

and:

Signal.trap("USR1") do
  $debug = !$debug
  puts "Debug now: #$debug"
end
like image 533
aug2uag Avatar asked Oct 20 '25 23:10

aug2uag


1 Answers

Those two are totally different. The first is a debugging line executed only if $DEBUG is set; $DEBUG is set if you pass the command-line argument -d to ruby.

The second is flipping a $debug variable (different case!!), which is specific to the program. When you hit the process with a SIGUSR1 signal, it will change the debug mode (useful for getting it to print debugging information only sometimes).

like image 151
nneonneo Avatar answered Oct 24 '25 19:10

nneonneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!