module Scorched::DynamicDelegate

Unlike most delegator’s that delegate to an object, this delegator delegates to a runtime expression, and so the target object can be dynamic.

Public Instance Methods

alias_each(methods) { |m| ... } click to toggle source
# File lib/scorched/dynamic_delegate.rb, line 16
def alias_each(methods)
  methods.each do |m|
    alias_method yield(m), m
  end
end
delegate(target_literal, *methods) click to toggle source
# File lib/scorched/dynamic_delegate.rb, line 5
    def delegate(target_literal, *methods)
      methods.each do |method|
        method = method.to_sym
        class_eval <<-CODE
          def #{method}(*args, &block)
            #{target_literal}.__send__(#{method.inspect}, *args, &block)
          end
        CODE
      end
    end