aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/delegation.rb
diff options
context:
space:
mode:
authorDaniel Schierbeck <daniel.schierbeck@gmail.com>2008-09-14 23:20:51 +0200
committerMichael Koziarski <michael@koziarski.com>2008-10-19 13:42:52 +0200
commit731c63f8ebc93e703b1a114d86f4f9f694ae48bf (patch)
tree53adee407b1874dc2a0d4eb48375df196406e993 /activesupport/lib/active_support/core_ext/module/delegation.rb
parent6d1d48de6a16b0ff4e4533cccf00c0ec747feefb (diff)
downloadrails-731c63f8ebc93e703b1a114d86f4f9f694ae48bf.tar.gz
rails-731c63f8ebc93e703b1a114d86f4f9f694ae48bf.tar.bz2
rails-731c63f8ebc93e703b1a114d86f4f9f694ae48bf.zip
Added :prefix option to Module#delegate.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index e0b5f3e379..fee4454cb2 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -53,9 +53,11 @@ class Module
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
end
+ prefix = options[:prefix] ? "#{to}_" : ""
+
methods.each do |method|
module_eval(<<-EOS, "(__DELEGATION__)", 1)
- def #{method}(*args, &block)
+ def #{prefix}#{method}(*args, &block)
#{to}.__send__(#{method.inspect}, *args, &block)
end
EOS