Forum: Ruby on Rails How to put common utils in the app without polluing environm

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.
934f858e451cf9b771996b2940cd696b?d=identicon&s=25 Raj Singh (dorelal)
on 2007-01-26 19:17
(Received via mailing list)
I have developed some common utils which I use in all my RoR apps.
It's a moule with a lot of utilities. In order t use them currently
this is what I do.

environment.rb
  include AppCommonUtils


The file app_common_utils reside in lib directory. It works but I don't
like it.

In order to use these utilities I need to tinker with the
environment.rb of each application. So I put this module as a pluging.
But in int init.rb of the plugin I don't know what to write which will
be equivalent of putting the module in the environment.rb.

I'm suspecting it will be something along the line of

something.send(:include, AppCommonUtils)

Could someone help me out with what that something should be here?

Thanks
72ee7b478a235f646c3495f03ebbe676?d=identicon&s=25 Andrew Stewart (Guest)
on 2007-01-29 16:49
(Received via mailing list)
>
> In order to use these utilities I need to tinker with the
> environment.rb of each application. So I put this module as a pluging.
> But in int init.rb of the plugin I don't know what to write which will
> be equivalent of putting the module in the environment.rb.
>
> I'm suspecting it will be something along the line of
>
> something.send(:include, AppCommonUtils)

Rails will load your AppCommonUtils module automatically without your
having to tinker with environment.rb.

If you want to include your module, i.e. above and beyond the
auto-'require' I just mentioned, you could try something like this
(though I'm not 100% sure about this) inside your module:

module AppCommonUtils
   def self.included(base)
     base.extend self
   end
end

Regards,
Andy Stewart
934f858e451cf9b771996b2940cd696b?d=identicon&s=25 Raj Singh (dorelal)
on 2007-01-31 03:30
(Received via mailing list)
The module AppCommonUtils needs to be included in environment.rb for
it to be invoked. Otherwise I don't think it'll work.

- Neeraj
This topic is locked and can not be replied to.