diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-09 04:59:26 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-09 04:59:26 -0800 |
commit | 6d808cf494e0434c814c0be9594020ad6f00ef18 (patch) | |
tree | a0ccd7e367784eb01ef37b75c092cbc0f4756457 /activeresource | |
parent | 7f0fcadd3650eaee5bd6a8ab8032ed3c5627385b (diff) | |
download | rails-6d808cf494e0434c814c0be9594020ad6f00ef18.tar.gz rails-6d808cf494e0434c814c0be9594020ad6f00ef18.tar.bz2 rails-6d808cf494e0434c814c0be9594020ad6f00ef18.zip |
Remove reliance on string access core extension
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index bd2abdd38e..bfe4208d98 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1152,15 +1152,16 @@ module ActiveResource def respond_to?(method, include_priv = false) method_name = method.to_s if attributes.nil? - return super + super elsif attributes.has_key?(method_name) - return true - elsif ['?','='].include?(method_name.last) && attributes.has_key?(method_name.first(-1)) - return true + true + elsif method_name =~ /(?:=|\?)$/ && attributes.include?($`) + true + else + # super must be called at the end of the method, because the inherited respond_to? + # would return true for generated readers, even if the attribute wasn't present + super end - # super must be called at the end of the method, because the inherited respond_to? - # would return true for generated readers, even if the attribute wasn't present - super end protected @@ -1249,13 +1250,15 @@ module ActiveResource def method_missing(method_symbol, *arguments) #:nodoc: method_name = method_symbol.to_s - case method_name.last + if method_name =~ /(=|\?)$/ + case $1 when "=" - attributes[method_name.first(-1)] = arguments.first + attributes[$`] = arguments.first when "?" - attributes[method_name.first(-1)] - else - attributes.has_key?(method_name) ? attributes[method_name] : super + attributes[$`] + end + else + attributes.include?(method_name) ? attributes[method_name] : super end end end |