Sha256: 7bbe8c6469121ddc1e59665391f4f7af0b278713c534be6a3eb67265657873e9
Contents?: true
Size: 818 Bytes
Versions: 2
Compression:
Stored size: 818 Bytes
Contents
module Spank class Proxy def initialize(target) @target = target end def add_interceptor(method, interceptor) self.extend(create_module_for(method, interceptor)) self end private def create_invocation_for(method, args, block) Invocation.new(@target, method, args, block) end def method_missing(method, *args, &block) if block @target.public_send(method, *args, block) else @target.public_send(method, *args) end end def create_module_for(method, interceptor) Module.new do define_method(method.to_sym) do |*args, &block| invocation = create_invocation_for(method, args, block) interceptor.intercept(invocation) invocation.result end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spank-0.0.2 | lib/spank/proxy.rb |
spank-0.0.1 | lib/spank/proxy.rb |