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.110 lib/ghostable.rb
tbpgr_utils-0.0.109 lib/ghostable.rb
tbpgr_utils-0.0.108 lib/ghostable.rb
tbpgr_utils-0.0.107 lib/ghostable.rb
tbpgr_utils-0.0.106 lib/ghostable.rb
tbpgr_utils-0.0.105 lib/ghostable.rb
tbpgr_utils-0.0.104 lib/ghostable.rb
tbpgr_utils-0.0.103 lib/ghostable.rb
tbpgr_utils-0.0.102 lib/ghostable.rb
tbpgr_utils-0.0.101 lib/ghostable.rb
tbpgr_utils-0.0.100 lib/ghostable.rb
tbpgr_utils-0.0.99 lib/ghostable.rb
tbpgr_utils-0.0.98 lib/ghostable.rb
tbpgr_utils-0.0.97 lib/ghostable.rb
tbpgr_utils-0.0.96 lib/ghostable.rb
tbpgr_utils-0.0.95 lib/ghostable.rb
tbpgr_utils-0.0.94 lib/ghostable.rb
tbpgr_utils-0.0.93 lib/ghostable.rb
tbpgr_utils-0.0.92 lib/ghostable.rb
tbpgr_utils-0.0.91 lib/ghostable.rb