From: Rob Biedenharn Date: 2009-11-24T23:45:28+09:00 Subject: Re: What is __FILE__ and $0? (newbie question) On Nov 23, 2009, at 9:58 PM, Omar Campos wrote: > Hi, > > Thanks for your answer. I just wanted to understand a little better > what it meant. I don't like to include mystery code in my programs, > simply because someone says it works and because "you always need to > include that". I couldn't find these variables in the Ruby Book > included with the windows 1.8 distribution, and typing puts __FILE__ > on > the interactive ruby console didn't print anything useful (which now > makes perfect sense!). > > Once more, thanks. > -- > Posted via http://www.ruby-forum.com/. > That idiom is typically used to include test code within a file that is normally used as a library. The guarded code is run when: ruby foo.rb but not when bar.rb contains require 'foo' as others have pointed out. Now you should have a "why" to go with your "what" and "how" ;-) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com