diff options
author | Daniel Schierbeck <daniel.schierbeck@gmail.com> | 2008-09-21 15:27:50 +0200 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-10-19 13:42:52 +0200 |
commit | 32a58d2afc18c1ab6cb5a8b9fbd0ff981d7a714a (patch) | |
tree | 31370da06004d73fb0e7bd20e338eca66eb6e000 /activesupport/lib | |
parent | 0cb382cb6f51fbde8b22f6597b92d9bebb3445e7 (diff) | |
download | rails-32a58d2afc18c1ab6cb5a8b9fbd0ff981d7a714a.tar.gz rails-32a58d2afc18c1ab6cb5a8b9fbd0ff981d7a714a.tar.bz2 rails-32a58d2afc18c1ab6cb5a8b9fbd0ff981d7a714a.zip |
Added documentation of the new :prefix option.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index bd3afa1961..c457569b9a 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -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] |