Skip to content

Commit 5ce3831

Browse files
committed
Use send instead of instance_eval
1 parent b7052b8 commit 5ce3831

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

activemodel/lib/active_model/errors.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def add(attribute, message = nil, options = {})
6868
# Will add an error message to each of the attributes in +attributes+ that is empty.
6969
def add_on_empty(attributes, custom_message = nil)
7070
[attributes].flatten.each do |attribute|
71-
value = @base.instance_eval { read_attribute_for_validation(attribute) }
71+
value = @base.send(:read_attribute_for_validation, attribute)
7272
is_empty = value.respond_to?(:empty?) ? value.empty? : false
7373
add(attribute, :empty, :default => custom_message) unless !value.nil? && !is_empty
7474
end
@@ -77,7 +77,7 @@ def add_on_empty(attributes, custom_message = nil)
7777
# Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
7878
def add_on_blank(attributes, custom_message = nil)
7979
[attributes].flatten.each do |attribute|
80-
value = @base.instance_eval { read_attribute_for_validation(attribute) }
80+
value = @base.send(:read_attribute_for_validation, attribute)
8181
add(attribute, :blank, :default => custom_message) if value.blank?
8282
end
8383
end
@@ -146,7 +146,7 @@ def generate_message(attribute, message = :invalid, options = {})
146146
defaults = defaults.compact.flatten << :"messages.#{message}"
147147

148148
key = defaults.shift
149-
value = @base.instance_eval { read_attribute_for_validation(attribute) }
149+
value = @base.send(:read_attribute_for_validation, attribute)
150150

151151
options = { :default => defaults,
152152
:model => @base.class.name.humanize,

activemodel/lib/active_model/validations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def validates_each(*attrs)
6666
# Declare the validation.
6767
send(validation_method(options[:on]), options) do |record|
6868
attrs.each do |attr|
69-
value = record.instance_eval { read_attribute_for_validation(attr) }
69+
value = record.send(:read_attribute_for_validation, attr)
7070
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
7171
yield record, attr, value
7272
end

0 commit comments

Comments
 (0)