From 731c63f8ebc93e703b1a114d86f4f9f694ae48bf Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Sun, 14 Sep 2008 23:20:51 +0200 Subject: Added :prefix option to Module#delegate. Signed-off-by: Michael Koziarski --- activesupport/lib/active_support/core_ext/module/delegation.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb') 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 -- cgit v1.2.3