Sha256: 6536274cf99971c52987c9eb55f883801b21ff46013038e9fbc6d7421c8307a7
Contents?: true
Size: 864 Bytes
Versions: 2
Compression:
Stored size: 864 Bytes
Contents
module MethodFound =begin 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!!!" =end class Builder < Module attr_reader :interceptors # @yield Yields builder as context to block, to allow calling builder # methods to create interceptors in included class. def initialize @interceptors = [] super end def intercept(*args, &block) @interceptors.push(interceptor = Interceptor.new(*args, &block)) include interceptor end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
method_found-0.1.6 | lib/method_found/builder.rb |
method_found-0.1.5 | lib/method_found/builder.rb |