Permalink
Browse files

Remove unnecessary code from define_read_method and add assertion to …

…make sure the underscored version is actually generated
  • Loading branch information...
1 parent 1787447 commit ef95df7067342699b681b83e51c375bef0505b81 @jonleighton jonleighton committed Apr 15, 2011
@@ -66,10 +66,10 @@ def define_read_method(symbol, attr_name, column)
if cache_attribute?(attr_name)
access_code = "@attributes_cache['#{attr_name}'] ||= (#{access_code})"
end
- if symbol =~ /^[a-zA-Z_]\w*[!?=]?$/
- generated_attribute_methods.module_eval("def _#{symbol}; #{access_code}; end; alias #{symbol} _#{symbol}", __FILE__, __LINE__)
- else
- generated_attribute_methods.send(:define_method, symbol) { eval(access_code) }
+
+ generated_attribute_methods.module_eval do
+ define_method("_#{attr_name}") { eval(access_code) }
+ alias_method(attr_name, "_#{attr_name}")
end
end
end
@@ -75,6 +75,7 @@ def test_set_attributes_with_block
def test_respond_to?
topic = Topic.find(1)
assert_respond_to topic, "title"
+ assert_respond_to topic, "_title"
assert_respond_to topic, "title?"
assert_respond_to topic, "title="
assert_respond_to topic, :title

0 comments on commit ef95df7

Please sign in to comment.