Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8173 from nikitug/match_classes_without_to_s

Match classes without to_s conversions.
  • Loading branch information...
commit f9dc91731b6afe5e8cb32a992fe308f4f8781a55 2 parents eda34c4 + d2abfcb
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 activesupport/lib/active_support/core_ext/hash/conversions.rb
View
20 activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -94,17 +94,17 @@ def from_xml(xml)
private
def typecast_xml_value(value)
- case value.class.to_s
- when 'Hash'
+ case value
+ when Hash
if value['type'] == 'array'
_, entries = Array.wrap(value.detect { |k,v| not v.is_a?(String) })
if entries.nil? || (c = value['__content__'] && c.blank?)
[]
else
- case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a?
- when 'Array'
+ case entries # something weird with classes not matching here. maybe singleton methods breaking is_a?
+ when Array
entries.collect { |v| typecast_xml_value(v) }
- when 'Hash'
+ when Hash
[typecast_xml_value(entries)]
else
raise "can't typecast #{entries.inspect}"
@@ -135,10 +135,10 @@ def typecast_xml_value(value)
# how multipart uploaded files from HTML appear
xml_value['file'].is_a?(StringIO) ? xml_value['file'] : xml_value
end
- when 'Array'
+ when Array
value.map! { |i| typecast_xml_value(i) }
value.length > 1 ? value : value.first
- when 'String'
+ when String
value
else
raise "can't typecast #{value.class.name} - #{value.inspect}"
@@ -146,10 +146,10 @@ def typecast_xml_value(value)
end
def unrename_keys(params)
- case params.class.to_s
- when 'Hash'
+ case params
+ when Hash
Hash[params.map { |k,v| [k.to_s.tr('-', '_'), unrename_keys(v)] } ]
- when 'Array'
+ when Array
params.map { |v| unrename_keys(v) }
else
params
Please sign in to comment.
Something went wrong with that request. Please try again.