A Different Program Model

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


A source file in Ruby is different from one in Python in a few ways. First, in Ruby, it is not considered a module. A module in Ruby is somewhat different. Second, Ruby interprets your source file from top to bottom and compiles it into a syntax tree instead of bytecode. There is no equivalent to .pyc files. Third, all code is evaluated as part of the top-level program in the default private context of a special class, called Object. For example, when you define a function at this level, you are really defining a private method in the Object class. Finally, if you load or require external source files or extensions, they are evaluated at the point of insertion, as in Python. But no separately associated namespace is created for the loaded files/extensions themselvesthey are integrated into your code, within the current class binding.

You can reload source files simply by calling load again on the filename. You would use require for one-time loads and/or to load extensions. Refer to a Ruby reference (documenting the $: and $" variables) for related information.

Ruby does not have the notion of packages or __init__.py like Python, and there is not (yet) anything like Python's site or user modules. Distributing extensions and libraries can be done with Ruby's extconf.rb, or simply by placing a Ruby file at a known location.


   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net