Do Ruby 'require' statements go inside or outside the class definition?
at the top.
require 'rubygems'
require 'fastercsv'
class MyClass
# Do stuff with FasterCSV
end
Technically, it doesn't really matter. require
is just a normal method call, and the scope it's called in doesn't affect how it works. The only difference placement makes is that it will be executed when whatever code it's placed in is evaluated.
Practically speaking, you should put them at top so people can see the file's dependencies at a glance. That's the traditional place for it.