How do you include lib files

I have some additional Array methods I would like to make available, but
I can’t figure out how to load them.

Thanks for the help.

On 27 Aug 2008, at 07:25, Chris O. wrote:

I have some additional Array methods I would like to make available,
but
I can’t figure out how to load them.

require the file containing them.

Fred

Frederick C. wrote:

On 27 Aug 2008, at 07:25, Chris O. wrote:

I have some additional Array methods I would like to make available,
but
I can’t figure out how to load them.

require the file containing them.

Fred

Which is what I did. I thought rails provided a way to auto load them
at startup.

On 27 Aug 2008, at 08:03, Chris O. wrote:

Fred

Which is what I did. I thought rails provided a way to auto load them
at startup.

Well files in config/initializers are run on startup, you could
require it from there, other than that you are going to have to put
that require statement somewhere.

Fred

Frederick C. wrote:

On 27 Aug 2008, at 08:03, Chris O. wrote:

Fred

Which is what I did. I thought rails provided a way to auto load them
at startup.

Well files in config/initializers are run on startup, you could
require it from there, other than that you are going to have to put
that require statement somewhere.

Fred

Ah, I see. I was trying to add it to the load paths.

Thanks for the help

Chris O. wrote:

Which is what I did. I thought rails provided a way to auto load them
at startup.

The auto loader only works like this. Here’s the first time the
interpreter sees
Foo:

foo = Foo.new

That raises an exception which Rails catches. Then it tries to require
‘foo’,
based on the missing constant name.

That trick works only for things with a name. If foo.rb contains Bar,
then the
first instance of Bar, before a Foo, for any given interpretation, will
not load
foo.rb, and will propagate the exception.

You gotta remember this rule when building libraries. You could ensure
Foo
appears above Bar in every module, or you could require ‘foo’
explicitly.

And we put extensions to Ruby classes in environment.rb, but that might
just be
laziness!


Phlip

did you try with require ‘lib/yourfile’ in the application.html.erb
file?

On Aug 27, 2:25 am, Chris O. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs