Module: DynamicMethods::ClassMethods

Defined in:
lib/dynamic_methods.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_method(pattern, &method_definition) ⇒ Object

Define a dynamic method, accepts a RegEx pattern (optionally with captures) and a block which defines the method body. The block should expect at least as many arguments as capture groups are in the RegEx. e.g.

dynamic_method /render_(\w+)_(\w+) do |capture1, capture2, argument1, argument2|
  # do something
end


46
47
48
49
50
# File 'lib/dynamic_methods.rb', line 46

def dynamic_method pattern, &method_definition
  DynamicMethod.new(self, pattern, &method_definition).tap do |dynamic_method|
    dynamic_methods << dynamic_method
  end
end