How can class variables of a module be updated or accessed by methods availabe to that module by include/extend mechanisms?
Say module A has a class variable called @@foo; also that module includes/extends another B, which has some methods that would like to update class variables of the module, can they ?
For example, i want to write a module named, Options_Support, which provides support for defining command line options:
module Options_Support
module Class_Methods
def add_option(...)
# ...
end
end
module Instance_Methods
def options
# sum of all options defined
end
end
def self.included(receiver)
super
receiver.extend(Class_Methods)
receiver.send(:include, Instance_Methods)
end
end
Now module A wants some command line options specific to its behavior, so it wants to do this:
module A
include Options_Support
add_option :foo, '--foo' # ...
add_option :bar, '--bar' # ...
end
Object.new.extend(A).options # should sum up all options
Now foo, bar are options of module A and i want them to be stored in class variables of A, to do this methods in Options_Support module needs access to A's class variables. But how? Any ideas?