Skip to content

Lecture 02

marekjelen edited this page Oct 3, 2011 · 21 revisions

Separating code into files

In Ruby code can be separated into files. To load code from file use require

require "somefile.extension"

File with extension [rb, so, o, dll, bundle, jar] can be addressed without the extension. Having a file called somefile.rb these two are equivalent

require "somefile"
require "somefile.rb"

The file, if it is not absolute path, will be looked from paths contained in $: variable. $: is Array and user is free to add it's own paths or delete others. Required files are tracked in variable $". If a path is already in $", than it will not be required again. $" is also Array and user is free to modify it.

Opening classes

Clone this wiki locally