4 PARAM_PATTERN = /(\$\w*)/
5 PARAM_OR_GROUP_PATTERN = /(\$\w*)|\(.*?\)/
8 def initialize(name, &block)
10 assign_expression(name)
11 init_module(name, &block)
14 def perform(instance, *args)
16 instance.__send__(sanitize(@name), *args)
19 def init_module(name, &block)
20 sanitized_name = sanitize(name)
22 define_method(sanitized_name, &block)
26 def sanitize(a_string_or_regexp)
27 return a_string_or_regexp.source if Regexp == a_string_or_regexp
28 a_string_or_regexp.to_s
33 !(matches = name.match(@expression)).nil?
37 name.match(@expression)[1..-1]
42 def assign_expression(name)
44 if String === expression
45 expression.gsub! '(', '\('
46 expression.gsub! ')', '\)'
47 while expression =~ PARAM_PATTERN
48 expression.gsub!($1, "(.*?)")
51 @expression = Regexp.new("^#{expression}$")