diff options
author | Joshua Peek <josh@joshpeek.com> | 2011-03-30 20:56:05 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2011-03-30 20:56:05 -0500 |
commit | 5df076ad0965dc684afff8a019fd9f92a53ada76 (patch) | |
tree | b2272d3d7f0ed6713d888390a13b130c65aec6f3 /activemodel/lib/active_model/attribute_methods.rb | |
parent | ac9443ed71bf0b40cf5b321e8e1b77b98abd9b5e (diff) | |
parent | 9772de8d459960cc114c5b214343b7ce08fea21c (diff) | |
download | rails-5df076ad0965dc684afff8a019fd9f92a53ada76.tar.gz rails-5df076ad0965dc684afff8a019fd9f92a53ada76.tar.bz2 rails-5df076ad0965dc684afff8a019fd9f92a53ada76.zip |
Merge branch 'master' into sprockets
Diffstat (limited to 'activemodel/lib/active_model/attribute_methods.rb')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 73468afe55..be55581c66 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -106,8 +106,14 @@ module ActiveModel if block_given? sing.send :define_method, name, &block else - value = value.to_s if value - sing.send(:define_method, name) { value && value.dup } + 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 |