aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-08-30 14:08:10 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-09-09 14:37:58 -0700
commitd79b1aa0ba96641fd6d8c9f4e79fae27e4fa9a83 (patch)
tree3ce3ce0f17b6922c2ed8613ee52b988ae2d0052e /activemodel/lib/active_model
parentcb67d166297ff6745358b804c61277c902e87023 (diff)
downloadrails-d79b1aa0ba96641fd6d8c9f4e79fae27e4fa9a83.tar.gz
rails-d79b1aa0ba96641fd6d8c9f4e79fae27e4fa9a83.tar.bz2
rails-d79b1aa0ba96641fd6d8c9f4e79fae27e4fa9a83.zip
Fewer object allocations
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 149f6abf61..44e3e64a9e 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -317,7 +317,7 @@ module ActiveModel
private
class AttributeMethodMatcher
- attr_reader :prefix, :suffix
+ attr_reader :prefix, :suffix, :method_missing_target
AttributeMethodMatch = Struct.new(:target, :attr_name)
@@ -325,22 +325,20 @@ module ActiveModel
options.symbolize_keys!
@prefix, @suffix = options[:prefix] || '', options[:suffix] || ''
@regex = /^(#{Regexp.escape(@prefix)})(.+?)(#{Regexp.escape(@suffix)})$/
+ @method_missing_target = :"#{@prefix}attribute#{@suffix}"
+ @method_name = "#{prefix}%s#{suffix}"
end
def match(method_name)
- if matchdata = @regex.match(method_name)
- AttributeMethodMatch.new(method_missing_target, matchdata[2])
+ if @regex =~ method_name
+ AttributeMethodMatch.new(method_missing_target, $2)
else
nil
end
end
def method_name(attr_name)
- "#{prefix}#{attr_name}#{suffix}"
- end
-
- def method_missing_target
- :"#{prefix}attribute#{suffix}"
+ @method_name % attr_name
end
end
end