Sha256: 83f461c7519a798b400a39c32ae4fe215de30b3827512f3b9c90b72d91cd98c9
Contents?: true
Size: 1.58 KB
Versions: 3
Compression:
Stored size: 1.58 KB
Contents
# 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ro_commands-0.0.3 | lib/ro_commands/ro_helper.rb |
ro_commands-0.0.2 | lib/ro_commands/ro_helper.rb |
ro_commands-0.0.1 | lib/ro_commands/ro_helper.rb |