Let's say I have some custom classes that are not related to models, controllers, etc., should I put this in / lib correctly?
On rails <3 I would add this directory to my loadpath, and on rails 3+ I would add this to my autoload_path. Is it correct?
Now say that I have some classes that extend already defined classes. Where should I put this so that it starts at startup. For example, I want to add the 'foo' method to a String.
class String
def foo
'foo;
end
end
Where should I put this class so that it is defined at startup?
Another weird mistake I come across is when I try to use namespace classes in lib.
module MyProject
class foo
end
end
Now in the console:
ruby-1.9.2-p136 :004 > MyProject::Foo
LoadError: Expected /Users/me/workspace/my_project/lib/foo.rb to define Foo
from /Users/rob/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:492:in `load_missing_constant'
from /Users/rob/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:183:in `block in const_missing'
. ?