Sha256: 3aa35c5f5664403f2f220eae44ce8a79e74e8b802563255d1cfb457d6ea00b9e

Contents?: true

Size: 744 Bytes

Versions: 14

Compression:

Stored size: 744 Bytes

Contents

class Module
  # Modified version from ActiveSupport to support :with (for additional arguments)
  def delegate(*methods)
    options = methods.pop
    unless options.is_a?(Hash) && to = options[:to]
      raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
    end

    prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
    with = options[:with] || []

    methods.each do |method|
      module_eval(<<-EOS, "(__DELEGATION__)", 1)
        def #{prefix}#{method}(*args, &block)
          args += [#{with * ", "}]
          #{to}.__send__(#{method.inspect}, *args, &block)
        end
      EOS
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
mojodna-switchboard-0.0.10 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.11 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.12 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.13 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.4 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.5 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.6 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.7 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.8 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.0.9 lib/switchboard/ext/delegate.rb
mojodna-switchboard-0.1.0 lib/switchboard/ext/delegate.rb
pkoch-switchboard-0.1.1b lib/switchboard/ext/delegate.rb
pkoch-switchboard-0.1.1a lib/switchboard/ext/delegate.rb
switchboard-0.1.0 lib/switchboard/ext/delegate.rb