14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rails_locale_sorter.rb', line 14
def self.convert_and_sort(object, deep = false)
if object.is_a?(Hash)
res = self.returning(RUBY_VERSION >= '1.9' ? Hash.new : ActiveSupport::OrderedHash.new) do |map|
object.each {|k, v| map[k] = deep ? convert_and_sort(v, deep) : v }
end
return res.class[res.sort {|a, b| a[0].to_s <=> b[0].to_s } ]
elsif deep && object.is_a?(Array)
array = Array.new
object.each_with_index {|v, i| array[i] = convert_and_sort(v, deep) }
return array
else
return object
end
end
|