2009-10-06 09:52:45 -04:00
|
|
|
|
|
|
|
module Rhino
|
|
|
|
class NativeObject
|
2009-10-06 10:04:57 -04:00
|
|
|
include Enumerable
|
2009-10-06 09:52:45 -04:00
|
|
|
attr_reader :j
|
2009-10-06 10:04:57 -04:00
|
|
|
|
2009-10-06 09:52:45 -04:00
|
|
|
def initialize(j)
|
|
|
|
@j = j
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](k)
|
2009-10-06 14:20:37 -04:00
|
|
|
To.ruby @j.get(k.to_s, @j)
|
2009-10-06 09:52:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def []=(k,v)
|
2009-11-09 10:45:23 -05:00
|
|
|
@j.put(k.to_s,@j,To.javascript(v))
|
2009-10-06 09:52:45 -04:00
|
|
|
end
|
2009-10-06 10:04:57 -04:00
|
|
|
|
|
|
|
def each
|
|
|
|
for id in @j.getAllIds() do
|
|
|
|
yield id,@j.get(id,@j)
|
|
|
|
end
|
|
|
|
end
|
2009-11-08 23:25:25 -05:00
|
|
|
|
|
|
|
def to_h
|
|
|
|
{}.tap do |h|
|
|
|
|
each do |k,v|
|
|
|
|
h[k] = self.class === v ? v.to_h : v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_json(*args)
|
|
|
|
to_h.to_json(*args)
|
|
|
|
end
|
2009-10-06 09:52:45 -04:00
|
|
|
end
|
|
|
|
end
|