See p.528 of the pickaxe book (in appendix B).

I guess the difference is that irb parses line by line, but when you
send a file to ruby it parses the whole thing first. In the latter case,
the parser does not know that the variable is going to be defined when
execution reaches that point.

-- 

Joel VanderWerf
jskeeler / pacbell.net