Sha256: 3fb1d8f0131a90b9aa979f3c4f257d7c42d0821c69e2d930469a0a76f37d6fed
Contents?: true
Size: 1.1 KB
Versions: 5
Compression:
Stored size: 1.1 KB
Contents
module Tap module Support # Generates an Intern module for the specified method_name. # An Intern module: # - adds an accessor for <method_name>_block # - overrides <method_name> to call the block # def self.Intern(method_name) mod = INTERN_MODULES[method_name.to_sym] return mod unless mod == nil mod = INTERN_MODULES[method_name.to_sym] = Module.new mod.module_eval %Q{ attr_accessor :#{method_name}_block def #{method_name}(*inputs) raise "no #{method_name} block set" unless #{method_name}_block inputs.unshift(self) arity = #{method_name}_block.arity n = inputs.length unless n == arity || (arity < 0 && (-1-n) <= arity) raise ArgumentError.new("wrong number of arguments (\#{n} for \#{arity})") end #{method_name}_block.call(*inputs) end } mod end # An array of already-declared intern modules, # keyed by method_name. INTERN_MODULES = {} # An Intern module for :process. Intern = Support.Intern(:process) end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
tap-0.12.3 | lib/tap/support/intern.rb |
tap-0.12.4 | lib/tap/support/intern.rb |
tap-0.12.2 | lib/tap/support/intern.rb |
tap-0.12.0 | lib/tap/support/intern.rb |
tap-0.12.1 | lib/tap/support/intern.rb |