Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure to reset defined methods after calling attribute_method_suffix

  • Loading branch information...
commit 1ae7eb52006229f6d6975837f0ac1410e366d456 1 parent d599ea2
@josh josh authored
Showing with 7 additions and 9 deletions.
  1. +7 −9 activerecord/lib/active_record/attribute_methods.rb
View
16 activerecord/lib/active_record/attribute_methods.rb
@@ -34,8 +34,9 @@ module ClassMethods
# person.name = 'Hubert'
# person.name_changed? # => true
def attribute_method_suffix(*suffixes)
- attribute_method_suffixes.concat suffixes
+ attribute_method_suffixes.concat(suffixes)
rebuild_attribute_method_regexp
+ undefine_attribute_methods
end
# Returns MatchData if method_name is an attribute method.
@@ -101,12 +102,12 @@ def attribute_method_suffixes
# Evaluate the definition for an attribute related method
def evaluate_attribute_method(method_definition, method_name)
- generated_methods << method_name
+ generated_methods << method_name.to_s
begin
class_eval(method_definition, __FILE__, __LINE__)
rescue SyntaxError => err
- generated_methods.delete(method_name)
+ generated_methods.delete(method_name.to_s)
if logger
logger.warn "Exception occurred during reader method compilation."
logger.warn "Maybe #{method_name} is not a valid Ruby identifier?"
@@ -137,17 +138,14 @@ def method_missing(method_id, *args, &block)
end
end
- guard_private_attribute_method!(method_name, args)
if md = self.class.match_attribute_method?(method_name)
attribute_name, method_type = md.pre_match, md.to_s
if attribute_name == 'id' || @attributes.include?(attribute_name)
- __send__("attribute#{method_type}", attribute_name, *args, &block)
- else
- super
+ guard_private_attribute_method!(method_name, args)
+ return __send__("attribute#{method_type}", attribute_name, *args, &block)
end
- else
- super
end
+ super
end
# A Person object with a name attribute can ask <tt>person.respond_to?(:name)</tt>,
Please sign in to comment.
Something went wrong with that request. Please try again.