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

Version Path
tbpgr_utils-0.0.150 lib/ghostable.rb
tbpgr_utils-0.0.149 lib/ghostable.rb
tbpgr_utils-0.0.148 lib/ghostable.rb
tbpgr_utils-0.0.147 lib/ghostable.rb
tbpgr_utils-0.0.146 lib/ghostable.rb
tbpgr_utils-0.0.145 lib/ghostable.rb
tbpgr_utils-0.0.144 lib/ghostable.rb
tbpgr_utils-0.0.143 lib/ghostable.rb
tbpgr_utils-0.0.142 lib/ghostable.rb
tbpgr_utils-0.0.141 lib/ghostable.rb
tbpgr_utils-0.0.140 lib/ghostable.rb
tbpgr_utils-0.0.139 lib/ghostable.rb
tbpgr_utils-0.0.138 lib/ghostable.rb
tbpgr_utils-0.0.137 lib/ghostable.rb
tbpgr_utils-0.0.136 lib/ghostable.rb
tbpgr_utils-0.0.135 lib/ghostable.rb
tbpgr_utils-0.0.134 lib/ghostable.rb
tbpgr_utils-0.0.133 lib/ghostable.rb
tbpgr_utils-0.0.132 lib/ghostable.rb
tbpgr_utils-0.0.131 lib/ghostable.rb