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.90 lib/ghostable.rb
tbpgr_utils-0.0.89 lib/ghostable.rb
tbpgr_utils-0.0.88 lib/ghostable.rb
tbpgr_utils-0.0.87 lib/ghostable.rb
tbpgr_utils-0.0.86 lib/ghostable.rb
tbpgr_utils-0.0.85 lib/ghostable.rb
tbpgr_utils-0.0.84 lib/ghostable.rb
tbpgr_utils-0.0.83 lib/ghostable.rb
tbpgr_utils-0.0.82 lib/ghostable.rb
tbpgr_utils-0.0.81 lib/ghostable.rb
tbpgr_utils-0.0.80 lib/ghostable.rb
tbpgr_utils-0.0.79 lib/ghostable.rb
tbpgr_utils-0.0.78 lib/ghostable.rb
tbpgr_utils-0.0.77 lib/ghostable.rb
tbpgr_utils-0.0.76 lib/ghostable.rb
tbpgr_utils-0.0.75 lib/ghostable.rb
tbpgr_utils-0.0.74 lib/ghostable.rb
tbpgr_utils-0.0.73 lib/ghostable.rb
tbpgr_utils-0.0.72 lib/ghostable.rb
tbpgr_utils-0.0.71 lib/ghostable.rb