aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNikita Afanasenko <nikita@afanasenko.name>2012-11-11 16:53:39 +0400
committerNikita Afanasenko <nikita@afanasenko.name>2012-11-11 16:53:39 +0400
commitd2abfcbd8c55d5bfbbccaf0e34be8a67f4731ac3 (patch)
tree4e66348f58b971868fc8eb4607355eb02f5a390a /activesupport
parent12d6d3a6f8914d272529d79cba461759e2dedf09 (diff)
downloadrails-d2abfcbd8c55d5bfbbccaf0e34be8a67f4731ac3.tar.gz
rails-d2abfcbd8c55d5bfbbccaf0e34be8a67f4731ac3.tar.bz2
rails-d2abfcbd8c55d5bfbbccaf0e34be8a67f4731ac3.zip
Match classes without to_s conversions.
There is no need in `value_under_case.class.to_s` conversion since case already matches classes with `Class === value_under_case`.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 0e7bb179bf..85b0e10be2 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -94,17 +94,17 @@ class Hash
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 @@ class Hash
# 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 @@ class Hash
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