Arnaud Garcia wrote:> Hello,
>
> A simple question ... I would like to load a file at the initialization
> of my app, to populate and share an Hash in all my app.
>
> Where to do this kind of initialization ?
>
>
> I did something like @@myVar=File.open .... at the end of the file
> config/environment.rb , correct ?
>
> thanks
> arnaud
Define a little class for and stick in /lib it like so
#/lib/my_loader_thing.rb
class MyLoaderThing
cattr_accessor :data
def self.load
@@data = {
:foo => ''bar''
:baz => ''bingo''
}
end
end
Now in your environment.rb, at the bottom:
require ''my_loader_thing''
MyLoaderThing.load
Now throughout your app you can use that class attribute accessor like
so:
MyLoaderThing.data[:foo] #=> "bar"
--
Posted via http://www.ruby-forum.com/.