Hello,
I would like to load an Hash in my init.rb plugin file ... than I would
like to use this hash in my module ...
in my init.rb:
@anHash = load From file...
in mymodule:
module Amodule
def myFunction
#@anHash ....
end
end
How can I access to my hash in my plugin module function ?
thanks for this dummy question ;-)
Arnaud
Why not define a method in your module which loads the Hash, and then
call this method within init.rb? In general, you need to be careful
about creating variables and objects in init.rb, since the bindings
under which the file is evaluated can cause scope weirdness under some
circumstances.
Anyway - something like this.
my_plugin/lib/my_module.rb
---------------------------------------
module MyModule
def self.load(filename)
@data = YAML.load(.....)
end
def self.use_data
# do whatever you want with @data
end
end
my_plugin/init.rb
------------------------
MyModule.load(''filename.yml'')
HTH
- james
On 7/27/06, Arnaud Garcia <arnaud.garcia@sim.hcuge.ch>
wrote:> Hello,
>
> I would like to load an Hash in my init.rb plugin file ... than I would
> like to use this hash in my module ...
>
> in my init.rb:
>
> @anHash = load From file...
>
>
>
> in mymodule:
>
> module Amodule
> def myFunction
> #@anHash ....
> end
> end
>
> How can I access to my hash in my plugin module function ?
>
> thanks for this dummy question ;-)
>
>
> Arnaud
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
* J *
~
cool, it is a better design ... arnaud James Adam a ?crit :> Why not define a method in your module which loads the Hash, and then > call this method within init.rb? In general, you need to be careful > about creating variables and objects in init.rb, since the bindings > under which the file is evaluated can cause scope weirdness under some > circumstances. > > Anyway - something like this. > > my_plugin/lib/my_module.rb > --------------------------------------- > module MyModule > def self.load(filename) > @data = YAML.load(.....) > end > def self.use_data > # do whatever you want with @data > end > end > > > my_plugin/init.rb > ------------------------ > MyModule.load(''filename.yml'') > > > HTH > > - james > > On 7/27/06, Arnaud Garcia <arnaud.garcia@sim.hcuge.ch> wrote: > >> Hello, >> >> I would like to load an Hash in my init.rb plugin file ... than I would >> like to use this hash in my module ... >> >> in my init.rb: >> >> @anHash = load From file... >> >> >> >> in mymodule: >> >> module Amodule >> def myFunction >> #@anHash .... >> end >> end >> >> How can I access to my hash in my plugin module function ? >> >> thanks for this dummy question ;-) >> >> >> Arnaud >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > >