I am trying to iterate through my array separated by white space:
diff_attr = []
%w[name hours].each do |a|
if @old_place.a != new_place[a.to_sym]
diff_attr << a
end
end
I want to compare attributes (name and hours) of two different objects. Right now, I’m getting an undefined method ‘a’ error. Right now, a is being evaluated as a method of @old_place instead of as a variable.
How do I evaluate the iterator inside the block so that I’m comparing:
@old.place.name != new_place[:name]
instead of
@old.place.a != new_place[:a]
Well, you can either do it like you’re doing for
new_place(assuming both are ActiveRecord objects):Or, use
Object#send: