module RegexMethod

Constants

VERSION

Attributes

regex_methods[RW]

Public Class Methods

included(base) click to toggle source
# File lib/regex_method.rb, line 28
def self.included(base)
        base.extend ClassMethods
        base.class_eval do 
                class << self
                        attr_accessor :regex_methods
                end
                self.regex_methods = {}
        end
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/regex_method.rb, line 11
def method_missing(method, *args, &block)
        self.class.regex_methods.each do |regex_method_name, proc|
                if matched_data = method.to_s.match(Regexp.new(regex_method_name))
                        regex_method_args = matched_data[1..-1].concat(args)
                        return proc.call(*regex_method_args)
                end
        end
        super
end
respond_to?(method) click to toggle source
Calls superclass method
# File lib/regex_method.rb, line 21
def respond_to?(method)
        self.class.regex_methods.each do |regex_method_name, proc|
                return true if method.to_s.match(Regexp.new(regex_method_name))
        end
        super
end