class ForwardingDsl::Dsl

Attributes

that[RW]
this[RW]

Public Class Methods

new(this, that) click to toggle source
# File lib/forwarding_dsl/dsl.rb, line 20
def initialize this, that
  @this = this
  @that = that
end
run(target, &block) click to toggle source
# File lib/forwarding_dsl/dsl.rb, line 6
def self.run target, &block
  return target unless block_given?

  case block.arity
  when 0 then
    new(target, block.binding.eval('self')).
      send(:instance_exec, &block)
  when 1 then
    block.call target
  else
    raise ArgumentError.new "Wrong number of arguments. Pass 1 or none."
  end
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
# File lib/forwarding_dsl/dsl.rb, line 25
def method_missing name, *args, &block
  if this.respond_to? name
    this.public_send name, *args, &block
  else
    that.public_send name, *args, &block
  end
end
respond_to_missing?(name, *args) click to toggle source
Calls superclass method
# File lib/forwarding_dsl/dsl.rb, line 33
def respond_to_missing? name, *args
  this.respond_to?(name, *args) ||
    that.respond_to?(name, *args) ||
    super
end