Class: HookLyingSyncer

Inherits:
Object
  • Object
show all
Defined in:
lib/hook_lying_syncer.rb,
lib/hook_lying_syncer/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Constructor Details

#initialize(object, matcher, &block) ⇒ HookLyingSyncer

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.



17
18
19
20
21
# File 'lib/hook_lying_syncer.rb', line 17

def initialize(object, matcher, &block)
  @object = object
  @matcher = matcher
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object (private)



30
31
32
33
34
35
36
37
# 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