I don’t have access to an instance of Ruby at the moment and I am not
clear what is being said in The Ruby P.ming Language (Flanagan &
Matsumoto). It says require code is executed immediately. It also says
you can’t insert the require code in the middle of something as if you
are copy-and-pasting, so can you explain some basics of what actually
If I have a file myprog.rb and libfile1.rb, and I run myprog:
… I believe Ruby will run statement 1 and then run statement 2
Now if I change this to:
…I assume Ruby only runs statement 1 and stops
Now if I change myprog:
…well, can you do that? If you can, presumably Ruby reads libfile1 but
doesn’t execute it?
Also does require get executed in the order of text encountered in the
file or does the Ruby runtime pick out the keyword require up front and
expand it before the native code?
Does this do 1 then 2 or 2 first?
What are the differences between wrapping require code in ‘Module’,
‘Def’ and ‘Class’?
The final question is in typical web environments like webrick, apache
or eruby, does the require code get loaded and ‘compiled’ everytime any
program refers to it or is there some mechanism to cache common code in