0001-forwardable-doc-def_delegator-with-example.patch

doc def_delegator - Sandor Szücs, 05/21/2011 07:38 PM

Download (1.11 KB)

View differences:

lib/forwardable.rb
175 175
    end
176 176
  end
177 177

  
178
  # Define +method+ as delegator instance method with an optional
179
  # alias name +ali+. Method calls to +ali+ will be delegated to
180
  # +accessor.method+. 
181
  #
182
  #   class MyQueue
183
  #     extend Forwardable
184
  #     attr_reader :queue
185
  #     def initialize
186
  #       @queue = []
187
  #     end
188
  #     
189
  #     def_delegator :@queue, :push, :mypush
190
  #   end
191
  #
192
  #   q = MyQueue.new
193
  #   q.mypush 42
194
  #   q.queue    #=> [42]
195
  #   q.push 23  #=> NoMethodError
196
  #
178 197
  def def_instance_delegator(accessor, method, ali = method)
179 198
    line_no = __LINE__; str = %{
180 199
      def #{ali}(*args, &block)
181
-