Forum: Ruby on Rails Using functionality in /lib in initializers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Da673e0d9cea081c001b281a09699cd0?d=identicon&s=25 tekwiz (Guest)
on 2009-03-19 23:09
(Received via mailing list)
I need to use some functionality that I've added to the Hash class in
an initializer.  I've written the functionality into /lib/hash.rb;
however, rails apparently loads the files in /lib after the
initializers as the methods are not there to use in the initializer.

I've used a require statement at the top of the initializer to get the
functionality...
   require File.join(RAILS_ROOT, 'lib', 'hash')

It works and no warnings are being thrown in the log; however, since
rails doesn't load them until after the initializers, I wanted to
ask... Is this unsafe in some way?

-- TW
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-19 23:25
(Received via mailing list)
On Mar 19, 10:08 pm, tekwiz <twarl...@gmail.com> wrote:
> I need to use some functionality that I've added to the Hash class in
> an initializer.  I've written the functionality into /lib/hash.rb;
> however, rails apparently loads the files in /lib after the
> initializers as the methods are not there to use in the initializer.
>
Except perhaps in production mode, rails won't magically load files
from lib for you (and event then that loading happens before
initializers run)

> I've used a require statement at the top of the initializer to get the
> functionality...
>    require File.join(RAILS_ROOT, 'lib', 'hash')

Just require 'hash' would do

Fred
Da673e0d9cea081c001b281a09699cd0?d=identicon&s=25 tekwiz (Guest)
on 2009-03-20 01:40
(Received via mailing list)
Ahh, I see! Thanks Fred!

-- TW

On Mar 19, 5:25 pm, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.