[Rails] accessing a variable inside a plugin
Arnaud Garcia
arnaud.garcia at sim.hcuge.ch
Thu Jul 27 10:18:29 GMT 2006
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 at 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 at lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
More information about the Rails
mailing list