class MethodFound::Builder
Creates set of interceptors to include into a class.
@example
class Post builder = MethodFound::Builder.new { intercept /\Asay_([a-z]+)\Z/ do |method_name, matches, *arguments| "#{matches[1]}!" end intercept /\Ayell_([a-z]+)\Z/ do |method_name, matches, *arguments| "#{matches[1]}!!!" end } end foo = Foo.new foo.say_hello #=> "hello!" foo.yell_hello #=> "hello!!!"
Attributes
interceptors[R]
Public Class Methods
new()
click to toggle source
@yield Yields builder as context to block, to allow calling builder
methods to create interceptors in included class.
Calls superclass method
# File lib/method_found/builder.rb, line 30 def initialize @interceptors = [] super end
Public Instance Methods
intercept(*args, &block)
click to toggle source
# File lib/method_found/builder.rb, line 35 def intercept(*args, &block) @interceptors.push(interceptor = Interceptor.new(*args, &block)) include interceptor end