aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-03-27 00:21:25 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-03-27 00:21:25 +0530
commit2fc32636dc07cd4986e065be2ab3fbded34cbe18 (patch)
tree7ceb3541e30d5559b0f51093f27970485d505f7e /activemodel/lib/active_model/attribute_methods.rb
parent547407a9fb375601deb0834fb1c2d9a108c9aea1 (diff)
parent7c6807296b114f0688e6e74494f1d43d3a0548ba (diff)
downloadrails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.gz
rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.bz2
rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activemodel/lib/active_model/attribute_methods.rb')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 2a99450a3d..be55581c66 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -106,11 +106,14 @@ module ActiveModel
if block_given?
sing.send :define_method, name, &block
else
- # use eval instead of a block to work around a memory leak in dev
- # mode in fcgi
- sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
- def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end
- eorb
+ if name =~ /^[a-zA-Z_]\w*[!?=]?$/
+ sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
+ def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end
+ eorb
+ else
+ value = value.to_s if value
+ sing.send(:define_method, name) { value }
+ end
end
end