diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-03-22 20:11:36 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-03-22 20:11:36 -0300 |
commit | 450f7cf01b855b536416fc048a92c4309da2492e (patch) | |
tree | 701225bdeb082efb37e4c5d75e6f0d9e12452183 /activemodel/lib | |
parent | baa237c974fee8023dd704a4efb418ff0e963de0 (diff) | |
download | rails-450f7cf01b855b536416fc048a92c4309da2492e.tar.gz rails-450f7cf01b855b536416fc048a92c4309da2492e.tar.bz2 rails-450f7cf01b855b536416fc048a92c4309da2492e.zip |
use class_eval with a string when it's possible
Diffstat (limited to 'activemodel/lib')
-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 f6648ea43e..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 } + 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 |