summaryrefslogtreecommitdiff
path: root/lib/forwardable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r--lib/forwardable.rb19
1 files changed, 19 insertions, 0 deletions
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)