Accessing a variable inside a plugin

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 :wink:

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

cool, it is a better design …
arnaud

James A. a écrit :