From bb34bcbe470d62b6dccac38ef0a1e8ee435b8530 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 22 May 2011 02:14:57 +0000 Subject: * lib/forwardable.rb: Document def_delegator. Patch by Sandor Szucs. [Ruby 1.9 - Bug #4752] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 ++++++- lib/forwardable.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bdf6e75d12..b22384e2b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ +Sun May 22 11:14:40 2011 Eric Hodel + + * lib/forwardable.rb: Document def_delegator. Patch by Sandor Szucs. + [Ruby 1.9 - Bug #4752] + Sun May 22 11:11:41 2011 Eric Hodel * lib/fileutils.rb: Document block behavior of FileUtils.cd. Patch by - Bil Kleb. [Ruby 1.9 - Bug 4751] + Bil Kleb. [Ruby 1.9 - Bug #4751] Sun May 22 11:07:47 2011 Eric Hodel diff --git a/lib/forwardable.rb b/lib/forwardable.rb index b43d00f568..2b71b904d0 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -175,6 +175,25 @@ module Forwardable end end + # Define +method+ as delegator instance method with an optional + # alias name +ali+. Method calls to +ali+ will be delegated to + # +accessor.method+. + # + # class MyQueue + # extend Forwardable + # attr_reader :queue + # def initialize + # @queue = [] + # end + # + # def_delegator :@queue, :push, :mypush + # end + # + # q = MyQueue.new + # q.mypush 42 + # q.queue #=> [42] + # q.push 23 #=> NoMethodError + # def def_instance_delegator(accessor, method, ali = method) line_no = __LINE__; str = %{ def #{ali}(*args, &block) -- cgit v1.2.3