Class: V8::Object

Inherits:
BasicObject
Defined in:
lib/kumogata/v8_object_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject



2
3
4
# File 'lib/kumogata/v8_object_ext.rb', line 2

def to_hash
  to_hash0(self)
end

#to_hash0(obj) ⇒ Object



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

def to_hash0(obj)
  case obj
  when V8::Array
    obj.map {|v| to_hash0(v) }
  when V8::Object
    h = {}
    obj.each do |k, v|
      h[to_hash0(k)] = to_hash0(v)
    end
    h
  else
    obj
  end
end