aboutsummaryrefslogtreecommitdiffstats
path: root/lib/forwardable.rb
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-20 13:33:08 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-20 13:33:08 +0000
commit57d8faeab4440e21b5a750ee346dc422a8745e89 (patch)
tree994f2ce192b5c9d328045b7da863fcdb65035cf2 /lib/forwardable.rb
parentdcb4ceeac68e32be46016930f0dc82b18e4694e6 (diff)
downloadruby-57d8faeab4440e21b5a750ee346dc422a8745e89.tar.gz
Revert r40839 for demo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r--lib/forwardable.rb38
1 files changed, 14 insertions, 24 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index ecc5f03843..0f8807aac1 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -19,40 +19,30 @@
# #record_number(), which simply calls #[] on the <tt>@records</tt>
# array, like this:
#
-# require 'forwardable'
-#
# class RecordCollection
-# attr_accessor :records
# extend Forwardable
# def_delegator :@records, :[], :record_number
# end
#
-# We can use the lookup method like so:
-#
-# r = RecordCollection.new
-# r.records = [4,5,6]
-# r.record_number(0) # => 4
-#
# Further, if you wish to provide the methods #size, #<<, and #map,
# all of which delegate to @records, this is how you can do it:
#
-# class RecordCollection # re-open RecordCollection class
+# class RecordCollection
+# # extend Forwardable, but we did that above
# def_delegators :@records, :size, :<<, :map
# end
-#
-# r = RecordCollection.new
-# r.records = [1,2,3]
-# r.record_number(0) # => 1
-# r.size # => 3
-# r << 4 # => [1, 2, 3, 4]
-# r.map { |x| x * 2 } # => [2, 4, 6, 8]
-#
-# You can even extend regular objects with Forwardable.
-#
-# my_hash = Hash.new
-# my_hash.extend Forwardable # prepare object for delegation
-# my_hash.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
-# my_hash.puts "Howdy!"
+# f = Foo.new
+# f.printf ...
+# f.gets
+# f.content_at(1)
+#
+# If the object isn't a Module and Class, You can too extend Forwardable
+# module.
+#
+# printer = String.new
+# printer.extend Forwardable # prepare object for delegation
+# printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
+# printer.puts "Howdy!"
#
# == Another example
#