Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix doc for using SingleForwardable with Module
The example for using SingleForwardable with
a Class or Module was incorrect Ruby (it
resulted in an exception).

Since the English sentence was not clear
about what the example was trying to document,
this is my best guess. The new example
illustrates that a Module can be delegated from
by extending it with SingleForwardable and
using `def_delegator`.
  • Loading branch information
Vladimir Andrijevik committed Jan 2, 2013
commit 33ba59a320776635635835d8c4f75bc68a0129b8
22 changes: 13 additions & 9 deletions lib/forwardable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,21 @@ def #{ali}(*args, &block)
# printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
# printer.puts "Howdy!"
#
# Also, SingleForwardable can be use to Class or Module.
# Also, SingleForwardable can be used to set up delegation for a Class or Module.
#
# module Facade
# extend SingleForwardable
# def_delegator :Implementation, :service
#
# class Implementation
# def service...
# end
# end
# class Implementation
# def self.service
# puts "serviced!"
# end
# end
#
# module Facade
# extend SingleForwardable
# def_delegator :Implementation, :service
# end
#
# Facade.service #=> serviced!
#
# If you want to use both Forwardable and SingleForwardable, you can
# use methods def_instance_delegator and def_single_delegator, etc.
module SingleForwardable
Expand Down