Class: Js2json::RubyScope

Inherits:
Object
  • Object
show all
Defined in:
lib/js2json/ruby_scope.rb

Defined Under Namespace

Classes: ObjectWrapper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_from_ruby_to_v8(obj) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/js2json/ruby_scope.rb', line 3

def self.convert_from_ruby_to_v8(obj)
  case obj
  when Array
    obj.map {|i| convert_from_ruby_to_v8(i) }
  when Hash
    Hash[*obj.map {|k, v|
      [
        convert_from_ruby_to_v8(k),
        convert_from_ruby_to_v8(v),
      ]
    }.flatten]
  when NilClass, Numeric, Proc, String, TrueClass, FalseClass
    obj
  else
    Js2json::RubyScope::ObjectWrapper.new(obj)
  end
end

Instance Method Details

#[](name) ⇒ Object

ObjectWrapper



59
60
61
62
# File 'lib/js2json/ruby_scope.rb', line 59

def [](name)
  obj = Module.const_get(name)
  Js2json::RubyScope.convert_from_ruby_to_v8(obj)
end