Class: BSON::OrderedHash

Inherits:
Object
  • Object
show all
Defined in:
lib/ghtorrent/bson_orderedhash.rb

Instance Method Summary collapse

Instance Method Details

#to_hObject

Convert a BSON result to a Hash



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ghtorrent/bson_orderedhash.rb', line 7

def to_h
  inject({}) do |acc, element|
    k, v = element;
    acc[k] = if v.class == Array then
               v.map{|x| if x.class == BSON::OrderedHash then x.to_h else x end}
             elsif v.class == BSON::OrderedHash then
               v.to_h
             else
               v
             end;
    acc
  end
end

#to_jsonObject



21
22
23
# File 'lib/ghtorrent/bson_orderedhash.rb', line 21

def to_json
  to_h.to_json
end