Class: Blockenspiel::Builder::Target

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/blockenspiel/builder.rb

Overview

This is a base class for dynamically constructed targets. The actual target class is an anonymous subclass of this base class.

Class Method Summary collapse

Methods included from DSL

included

Class Method Details

._add_methodinfo(name_, block_, yields_) ⇒ Object

Add a method specification to the subclass.



61
62
63
64
# File 'lib/blockenspiel/builder.rb', line 61

def self._add_methodinfo(name_, block_, yields_)
  (@_blockenspiel_methodinfo ||= {})[name_] = [block_, yields_]
  module_eval("def #{name_}(*params_, &block_); self.class._invoke_methodinfo(:#{name_}, params_, block_); end\n")
end

._invoke_methodinfo(name_, params_, block_) ⇒ Object

Attempt to invoke the given method on the subclass.



69
70
71
72
73
74
75
76
77
78
# File 'lib/blockenspiel/builder.rb', line 69

def self._invoke_methodinfo(name_, params_, block_)
  info_ = @_blockenspiel_methodinfo[name_]
  case info_[1]
  when :first
    params_.unshift(block_)
  when :last
    params_.push(block_)
  end
  info_[0].call(*params_, &block_)
end