From e8f2ecebfb86d33b9fd38a7788b3b0b7868d3f63 Mon Sep 17 00:00:00 2001 From: Jo Liss Date: Thu, 26 Jul 2012 00:27:17 +0200 Subject: [PATCH] Use blocks instead of eval to define methods --- lib/active_model/serializer.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 2547f680..edd99e46 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -318,7 +318,9 @@ module ActiveModel self._attributes = _attributes.merge(attr => options[:key] || attr.to_s.gsub(/\?$/, '').to_sym) unless method_defined?(attr) - class_eval "def #{attr}() object.read_attribute_for_serialization(:#{attr}) end", __FILE__, __LINE__ + define_method attr do + object.read_attribute_for_serialization(attr.to_sym) + end end end @@ -328,7 +330,9 @@ module ActiveModel attrs.each do |attr| unless method_defined?(attr) - class_eval "def #{attr}() object.#{attr} end", __FILE__, __LINE__ + define_method attr do + object.send attr + end end self._associations[attr] = klass.refine(attr, options) @@ -575,7 +579,7 @@ module ActiveModel end # Returns options[:scope] - def scope + def scope @options[:scope] end