summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-22 02:14:57 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-22 02:14:57 +0000
commitbb34bcbe470d62b6dccac38ef0a1e8ee435b8530 (patch)
tree28a5e1f84c94c9223037129b42b1d7bf57ffc83a
parent55aa4dce3bc550617e16de91eba315a41baac2b9 (diff)
* 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
-rw-r--r--ChangeLog7
-rw-r--r--lib/forwardable.rb19
2 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index bdf6e75d129..b22384e2b5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
+Sun May 22 11:14:40 2011 Eric Hodel <drbrain@segment7.net>
+
+ * lib/forwardable.rb: Document def_delegator. Patch by Sandor Szucs.
+ [Ruby 1.9 - Bug #4752]
+
Sun May 22 11:11:41 2011 Eric Hodel <drbrain@segment7.net>
* 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 <drbrain@segment7.net>
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index b43d00f568d..2b71b904d0a 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)