From 55dfa009769962367c58563480c9f776ae0f53ea Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 8 Aug 2016 01:19:32 +0200 Subject: [PATCH] explain why aliasing uses explicit selfs [ci skip] --- activesupport/lib/active_support/core_ext/module/aliasing.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/module/aliasing.rb b/activesupport/lib/active_support/core_ext/module/aliasing.rb index 83b94aa3cc..ccc4b0db3a 100644 --- a/activesupport/lib/active_support/core_ext/module/aliasing.rb +++ b/activesupport/lib/active_support/core_ext/module/aliasing.rb @@ -65,6 +65,9 @@ def alias_method_chain(target, feature) # e.subject = "Megastars" # e.title # => "Megastars" def alias_attribute(new_name, old_name) + # The following reader methods use an explicit `self` receiver in otder to + # support aliases that start with an uppercase letter. Otherwise, they would + # be resolved as constants instead. module_eval <<-STR, __FILE__, __LINE__ + 1 def #{new_name}; self.#{old_name}; end # def subject; self.title; end def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end