class HookLyingSyncer
Constants
- VERSION
Public Class Methods
new(object, matcher, &block)
click to toggle source
object is the object being wrapped, for purposes of endowing it with some pattern of methods it should respond to.
matcher is a lambda that returns any words of interest to the block, given the called method name. if there are any, it should return an array. if there are none, it may return an empty array, nil, or false, and the method name will be ass-u-me'd to be “not of interest”.
block is what you want to do with the object, the matches, and any additional args given to the dynamic method. ideally this should include actually declaring the method, so further uses won't be inefficiently done via method_missing. maybe a later version of hls will do that for you.
# File lib/hook_lying_syncer.rb, line 17 def initialize(object, matcher, &block) @object = object @matcher = matcher @block = block end
Private Instance Methods
find_matches(sym)
click to toggle source
# File lib/hook_lying_syncer.rb, line 39 def find_matches(sym) result = @matcher.call(sym) result ? result : [] end
method_missing(sym, *args, &blk)
click to toggle source
# File lib/hook_lying_syncer.rb, line 30 def method_missing(sym, *args, &blk) matches = find_matches(sym) if matches.any? @block.call(@object, matches, *args) else @object.send(sym, *args, &blk) end end
respond_to_missing?(sym, include_all=false)
click to toggle source
# File lib/hook_lying_syncer.rb, line 25 def respond_to_missing?(sym, include_all=false) matches = find_matches(sym) matches.any? ? true : @object.send(:respond_to?, sym, include_all) end