# gotchas: please use extend ::RoCommands::RoHelper, make sure module first extend 'method_added' method # example: # #module TryHelper # extend ::RoCommands::RoHelper # class << self # def _template_in_self # # end # end # # def _template_in_normal # # end #end module RoCommands module RoHelper class << self def included(base) base.extend(ClassMethods) end end module ClassMethods def meth_feature %r{^_} end def meths @meths.uniq! if @meths.respond_to?(:uniq!) @meths ||= [] end def method_added(meth) super #puts "method:#{meth}" def_meth(meth) end def singleton_method_added(meth) super #puts "singleton_method:#{meth}" def_meth(meth, 'singleton') end def def_meth(meth, meth_type=nil) meth = meth.to_s if defined?(meth_feature) and meth.match(meth_feature) if meth.match(%r{_}) new_method = meth.to_s.sub(%r{_}, "") if meth_type == 'singleton' define_singleton_method new_method.to_sym do |*args| before_each if defined? before_each send(meth.to_sym, *args) after_each if defined? after_each end else define_method new_method.to_sym do |*args| before_each if defined? before_each send(meth.to_sym, *args) after_each if defined? after_each end end end end end end end end