Module: Twitter::Delegation::ClassMethods

Defined in:
lib/core_ext/delegation.rb

Instance Method Summary collapse

Instance Method Details

#delegate(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/core_ext/delegation.rb', line 8

def delegate(*args)
  opts = args.last.is_a?(Hash) ? args.pop : {}
  if target = opts[:to]
    args.each do |sym|
      class_eval(<<-END, __FILE__, __LINE__)
        def #{sym}(*args, &block)
          send(#{target.inspect}) \
            .send(#{sym.inspect}, *args, &block)
        end
      END
    end
  else
    raise ArgumentError, "You must pass a target as :to option"
  end
end