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-23 22:42:36 +0200
committerPratik Naik <pratiknaik@gmail.com>2008-11-21 01:15:49 +0530
commita5156d9c2c3fe63f8b6a352199e51544ae28876a (patch)
treed6953be244d9c698b6bb638cafc2b58a645e03ad /activesupport/lib/active_support/core_ext/module/delegation.rb
parent206c5643aae40b0884d42fdb8caeb3f763936fa9 (diff)
downloadrails-a5156d9c2c3fe63f8b6a352199e51544ae28876a.tar.gz
rails-a5156d9c2c3fe63f8b6a352199e51544ae28876a.tar.bz2
rails-a5156d9c2c3fe63f8b6a352199e51544ae28876a.zip
Ensure only delegations to methods can have an automatic prefix. [#1235 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.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, 4 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 1ad18402e5..2905eebc85 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -78,6 +78,10 @@ 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
+ if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
+ raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
+ end
+
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
methods.each do |method|