Sha256: a497653ef0a70f74cfe8e148209cd6f68c3b4348f7205a978aba2398d1765652
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
require 'tap/utils' module Tap # Signal attaches an object and allows a specific method to be triggered # through a standard interface. class Signal class << self # A description of self attr_accessor :desc end # The object receiving signals through self. attr_reader :obj # An optional block, used at the signal's discretion (normally passed to # the method the signal targets on obj). attr_reader :block def initialize(obj, &block) @obj = obj @block = block end # Calls process with the input args and returns the result. def call(args) process(args) end # Simply returns the input args. def process(args) args end def inspect "#<#{self.class}:#{object_id}>" end protected def convert_to_array(obj, signature=[], options=false) return obj if obj.kind_of?(Array) argv = signature.collect {|key| obj[key] } if options opts = {} (obj.keys - signature).each do |key| opts[key] = obj[key] end argv << opts end argv end def convert_to_hash(obj, signature=[], remainder=nil) return obj if obj.kind_of?(Hash) args, argh = obj, {} signature.each do |key| argh[key] = args.shift end if remainder argh[remainder] = args end argh end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tap-1.4.0 | lib/tap/signal.rb |
tap-1.3.0 | lib/tap/signal.rb |