Sha256: c12366d25f209daa95d9611ba43741cac50d795e90cea873ca50454d7f72acaf
Contents?: true
Size: 758 Bytes
Versions: 141
Compression:
Stored size: 758 Bytes
Contents
# encoding: utf-8 require 'active_support/concern' module Ghostable extend ActiveSupport::Concern module ClassMethods def ghost_method(pattern, basename, &ghost_block) define_method basename do |method_name, *args, &block| self.class.class_eval { ghost_block.call(method_name, *args, &block) } end @patterns ||= {} @patterns[basename] = pattern tmp_patterns = @patterns.dup define_method :get_patterns do tmp_patterns end end end def method_missing(method_name, *args, &block) get_patterns.each do |basename, pattern| return method(basename).call(method_name, *args, &block) if method_name.to_s.match /#{pattern}/ end super end end
Version data entries
141 entries across 141 versions & 1 rubygems