My module definition looks like this:
module RG::Stats
def self.sum(a, args = {})
a.inject(0){ |accum, i| accum + i }
end
end
To use this method I simply require the file containing this definition so that I can do:
RG::Stats.sum(array)
and also
RG::Stats.method(:sum)
However, if I need to know the list of methods using RG::Stats.instance_methods
I get an empty array. This is because I have used self
. If I omit self
then RG::Stats.instance_methods
gives the list of methods, but I cannot access them anymore.
The question is: how to use self
in module's method definition?