Class: ProtoJ::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/proto_j/utils.rb

Class Method Summary collapse

Class Method Details

.to_sorted_hash(hash) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/proto_j/utils.rb', line 2

def self.to_sorted_hash(hash)
  if hash.is_a? Hash
    hash = Hash[hash.sort]
    hash.each_pair do |k,v|
      hash[k] = to_sorted_hash(v)
    end
    return hash
  elsif hash.is_a? Array
    return hash.collect do |item|
      to_sorted_hash(item)
    end
  else
    return hash
  end
end

.to_sorted_json(json) ⇒ Object



18
19
20
# File 'lib/proto_j/utils.rb', line 18

def self.to_sorted_json(json)
  to_sorted_hash(JSON.parse(json)).to_json
end