зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
55aa4dce3b
Коммит
bb34bcbe47
|
@ -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>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче