Skip to content

Commit

Permalink
Added documentation of the new :prefix option.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
dasch authored and NZKoz committed Oct 19, 2008
1 parent 0cb382c commit 32a58d2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions activesupport/lib/active_support/core_ext/module/delegation.rb
Expand Up @@ -47,6 +47,31 @@ class Module
# Foo.new.min # => 4
# Foo.new.max # => 11
#
# Delegates can optionally be prefixed using the <tt>:prefix</tt> option. If the value
# is <tt>true</tt>, the delegate methods are prefixed with the name of the object being
# delegated to.
#
# Person = Struct.new(:name, :address)
#
# class Invoice < Struct.new(:client)
# delegate :name, :address, :to => :client, :prefix => true
# end
#
# john_doe = Person.new("John Doe", "Vimmersvej 13")
# invoice = Invoice.new(john_doe)
# invoice.client_name # => "John Doe"
# invoice.client_address # => "Vimmersvej 13"
#
# It is also possible to supply a custom prefix.
#
# class Invoice < Struct.new(:client)
# delegate :name, :address, :to => :client, :prefix => :customer
# end
#
# invoice = Invoice.new(john_doe)
# invoice.customer_name # => "John Doe"
# invoice.customer_address # => "Vimmersvej 13"
#
def delegate(*methods)
options = methods.pop
unless options.is_a?(Hash) && to = options[:to]
Expand Down

0 comments on commit 32a58d2

Please sign in to comment.