debug flag being ignored

T

Tom Allison

I'm trying to run 'ruby -d foo.rb' and the d is either ignored or I don't
understand how it works. The code just runs as if there is no -d option.

Does this require something at compile time of Ruby that I might have overlooked?
 
L

Logan Capaldo

I'm trying to run 'ruby -d foo.rb' and the d is either ignored or I
don't understand how it works. The code just runs as if there is
no -d option.

Does this require something at compile time of Ruby that I might
have overlooked?

Maybe you wanted ruby -rdebug -d foo.rb ?
 
R

rickhg12hs

I'm trying to run 'ruby -d foo.rb' and the d is either ignored or I don't
understand how it works. The code just runs as if there is no -d option.

"-d" sets $DEBUG to true.

Does your code execute something when $DEBUG is true?

For example:

puts "Important intermediate value: #{my_critical_var}" if $DEBUG
 
K

Kedar Mhaswade

rickhg12hs wrote in post #131750:
"-d" sets $DEBUG to true.

Does your code execute something when $DEBUG is true?

For example:

puts "Important intermediate value: #{my_critical_var}" if $DEBUG

I was going nuts over this.
This file:
#!/usr/bin/env ruby
puts $DEBUG

prints false with or without ruby -d (e.g. ruby -d foo.rb)

So, the shebang line comes in the way in an unpredictable manner. The
workaround is to have export RUBYOPT=-d $RUBYOPT if you wanted shebang
line (and the easier invocation like: ./foo.rb after chmoding it).

If you are giving your file to the interpreter directly like: ruby
foo.rb (*and* you don't have shebang line in the file), then ruby -d
works as expected.

Bottom line: For such a simple thing, shebang line complicates life
(unnecessarily) at least on Linux :(
 
D

deepak

hi,
what does this output:

require 'rbconfig'
puts "topdir #{RbConfig::CONFIG['topdir']}"
puts "RUBY_DESCRIPTION: #{RUBY_DESCRIPTION}"

in both the cases,
1) ruby <script.rb> without the shebang
2) ./script.rb with the shebang after chmodding it

also do you have multiple versions of ruby on your system. one managed
by RVM and a system installed one on your path?

cheers,
deepak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top