From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-12-20T00:11:40+09:00 Subject: [ruby-talk:28939] Re: What's the Ruby way of doing: In article <3c20319c$0$23431$afc38c87@news.optusnet.com.au>, Nightblade wrote: >Hi all. > >I'm new to Ruby, so please don't shout. :-) Don't worry there's very little shouting in here... Most of us are still relatively newbie or at least we still remember being there recently ;-) >I used to really like doing >these kind of things in Perl: (example in metacode) > > $debug and print "some kind of message" > >and: > > unless $quiet print "extra info here" > >Is there a RubyWay(tm) to express this kind of Perl shorthand (besides using >a class)? > Well, if I understand what you're trying to do - you want to print something if a 'debug' variable is set... One thing to note: Ruby has a command line option ( -d ) that causes a global $DEBUG varible to be set to true if you use that option. Now, let's say you run your program (call it debugging.rb) like so: ruby -d debugging.rb then if debugging.rb contains a line like: print "this friendly debug message" if $DEBUG you'll see: this friendly debug message So, in general I think the way most folks use the form: print "something about debugging here" if $DEBUG (of course you could always use another variable in place of $DEBUG) You could also do (from your example above): print "extra info here" unless $quiet Phil