I have the following class, which I want to save all the desc fields into an array.
I'm going to be using this in multiple classes, so I thought to save some typing, I would use the module Describe.
module Describe
@@interactive = []
def desc(desc)
@desc = desc
end
def method_added(method)
@@interactive.push(@desc)
@desc = nil
end
end
This is what it looks like in the class.
class Dog
extend Describe
desc "Holy"
def bark
puts "woof"
end
desc "Moly"
def wag
puts "wagging"
end
end
Here is how I plan to use the code.
d = Dog.new
puts d.interactive
But I can't access the interactive array. I can't use a class, because if I try to use inheritance, the function desc isn't found. The same occurs when I try to use include instead of extend.
Is there any way for me to access the interactive array if I continue to use extend? Am I going about this problem incorrectly? Is there a way to make include run before the rest of my code so that the method desc is found?
What I'm trying to accomplish is dynamic documentation. I am trying to return to another program that I cannot control, the method name, the parameters and the description of each of these methods. I only asked about the description in the above question as the main issue I am having is that I do not know how to access the variable. I could just use code comments and parse those, but I wanted to make it clear to any programmer that came after me what my intent was and to prevent any unintentional comment accidents.
@@interactive? What do you want to do with it? As is, you accumulate strings, but don't refer to the variable. Are you trying to use it for dynamic documentation? Also, why doesmethod_added(method)take amethodparameter but not use it?