Skip to content
This repository
Browse code

Use send instead of instance_eval

  • Loading branch information...
commit 5ce3831faf684aea75948ce4602b6b9de361c11e 1 parent b7052b8
Pratik authored August 06, 2009
6  activemodel/lib/active_model/errors.rb
@@ -68,7 +68,7 @@ def add(attribute, message = nil, options = {})
68 68
     # Will add an error message to each of the attributes in +attributes+ that is empty.
69 69
     def add_on_empty(attributes, custom_message = nil)
70 70
       [attributes].flatten.each do |attribute|
71  
-        value = @base.instance_eval { read_attribute_for_validation(attribute) }
  71
+        value = @base.send(:read_attribute_for_validation, attribute)
72 72
         is_empty = value.respond_to?(:empty?) ? value.empty? : false
73 73
         add(attribute, :empty, :default => custom_message) unless !value.nil? && !is_empty
74 74
       end
@@ -77,7 +77,7 @@ def add_on_empty(attributes, custom_message = nil)
77 77
     # Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
78 78
     def add_on_blank(attributes, custom_message = nil)
79 79
       [attributes].flatten.each do |attribute|
80  
-        value = @base.instance_eval { read_attribute_for_validation(attribute) }
  80
+        value = @base.send(:read_attribute_for_validation, attribute)
81 81
         add(attribute, :blank, :default => custom_message) if value.blank?
82 82
       end
83 83
     end
@@ -146,7 +146,7 @@ def generate_message(attribute, message = :invalid, options = {})
146 146
       defaults = defaults.compact.flatten << :"messages.#{message}"
147 147
 
148 148
       key = defaults.shift
149  
-      value = @base.instance_eval { read_attribute_for_validation(attribute) }
  149
+      value = @base.send(:read_attribute_for_validation, attribute)
150 150
 
151 151
       options = { :default => defaults,
152 152
         :model => @base.class.name.humanize,
2  activemodel/lib/active_model/validations.rb
@@ -66,7 +66,7 @@ def validates_each(*attrs)
66 66
         # Declare the validation.
67 67
         send(validation_method(options[:on]), options) do |record|
68 68
           attrs.each do |attr|
69  
-            value = record.instance_eval { read_attribute_for_validation(attr) }
  69
+            value = record.send(:read_attribute_for_validation, attr)
70 70
             next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
71 71
             yield record, attr, value
72 72
           end

0 notes on commit 5ce3831

Please sign in to comment.
Something went wrong with that request. Please try again.