Remove reliance on string access core extension

This commit is contained in:
Jeremy Kemper 2009-11-09 04:59:26 -08:00
parent 7f0fcadd36
commit 6d808cf494

@ -1152,15 +1152,16 @@ def update_attributes(attributes)
def respond_to?(method, include_priv = false) def respond_to?(method, include_priv = false)
method_name = method.to_s method_name = method.to_s
if attributes.nil? if attributes.nil?
return super super
elsif attributes.has_key?(method_name) elsif attributes.has_key?(method_name)
return true true
elsif ['?','='].include?(method_name.last) && attributes.has_key?(method_name.first(-1)) elsif method_name =~ /(?:=|\?)$/ && attributes.include?($`)
return true 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 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 end
protected protected
@ -1249,13 +1250,15 @@ def split_options(options = {})
def method_missing(method_symbol, *arguments) #:nodoc: def method_missing(method_symbol, *arguments) #:nodoc:
method_name = method_symbol.to_s method_name = method_symbol.to_s
case method_name.last if method_name =~ /(=|\?)$/
case $1
when "=" when "="
attributes[method_name.first(-1)] = arguments.first attributes[$`] = arguments.first
when "?" when "?"
attributes[method_name.first(-1)] attributes[$`]
else end
attributes.has_key?(method_name) ? attributes[method_name] : super else
attributes.include?(method_name) ? attributes[method_name] : super
end end
end end
end end