From: Robert Klemme Date: 2004-09-09T02:40:06+09:00 Subject: Re: module_function question "Martin Pirker" schrieb im Newsbeitrag news:413f37ad$0$9314$3b214f66@aconews.univie.ac.at... > Hi... > away, too? (since we know all call_* are the same type and want to > remove that hand typed error source) Variant 1 module Mymodule def self.call_test1 printf "test1" end # module_function :call_test1 def self.call_test2 printf "test2" end # module_function :call_test2 def self.functions h = Hash.new methods.grep(/^call/).each do |f| h[f]=method(f) end h end end Mymodule.functions.each do |name, fun| fun.call puts " #{name}" end Variant 2 module Mymodule class << self def call_test1 printf "test1" end def call_test2 printf "test2" end def functions h = Hash.new methods.grep(/^call/).each do |f| h[f]=method(f) end h end end end Mymodule.functions.each do |name, fun| fun.call puts " #{name}" end Variant 3 module Mymodule module_function def call_test1 printf "test1" end def call_test2 printf "test2" end def functions h = Hash.new methods.grep(/^call/).each do |f| h[f]=method(f) end h end end Mymodule.functions.each do |name, fun| fun.call puts " #{name}" end Variant 4 module Mymodule module_function def call_test1 printf "test1" end def call_test2 printf "test2" end def functions h = Hash.new methods.each do |f| h[f]=method(f) if /^call/ =~ f end h end end Mymodule.functions.each do |name, fun| fun.call puts " #{name}" end Do you need more? robert