I've got a module that that has several classes defined within it. These
classes need to access some instance variables defined at the module
level.
For example:
module Evolvable
PC = 0.2
PM = 0.01
def Evolvable.init(pc=Evolvable::PC,pm=Evolvable::PM,crossovertype=:uniform)
@pc = pc
@pm = pm
@crossoverType = crossovertype
end
def Evolvable.get_pm
@pm
end
def Evolvable.get_pc
@pc
end
def Evolvable.get_crossoverType
@crossoverType
end
#and set methods too
class Population
def initialize
...
end
def do_crossover(pc=Evolvable.get_pc, type=Evolvable.get_crossoverType)
...
end
def do_mutate(pm=Evolvable.get_pm)
...
end
end
end
#and to use it:
Evolvable.init(0.2, 0.01, :two_point)
#..later...
Evolvable.set_crossoverType :uniform
#do more stuff
#end
Now this works ok, but I'm wondering if there's a way to create the
accessor methods for the Evolvable module automatically like with
attr_accessor and attr_reader. The problem with attr_accessor is that it
creates an instance method, not a module method - is there a way to
automatically create a module method?
Phil
--
"Or perhaps the truth is less interesting than the facts?"
Amy Weiss (accusing theregister.co.uk of engaging in 'tabloid journalism')
Senior VP, Communications
Recording Industry Association of America