Class: Js2json::RubyScope::ObjectWrapper
- Inherits:
-
Object
- Object
- Js2json::RubyScope::ObjectWrapper
- Defined in:
- lib/js2json/ruby_scope.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(obj) ⇒ ObjectWrapper
constructor
A new instance of ObjectWrapper.
Constructor Details
#initialize(obj) ⇒ ObjectWrapper
Returns a new instance of ObjectWrapper.
23 24 25 |
# File 'lib/js2json/ruby_scope.rb', line 23 def initialize(obj) @obj = obj end |
Instance Method Details
#[](name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/js2json/ruby_scope.rb', line 27 def [](name) name = name.to_s if name =~ /\A[A-Z]/ Js2json::RubyScope.convert_from_ruby_to_v8(@obj.const_get(name)) else proc do |*args| args.shift retval = nil if args.last.kind_of?(V8::Function) func = args.pop block = proc do |*block_args| block_args = block_args.map {|i| Js2json::RubyScope.convert_from_ruby_to_v8(i) } func.call(*block_args) end retval = @obj.send(name, *args, &block) else retval = @obj.send(name, *args) end Js2json::RubyScope.convert_from_ruby_to_v8(retval) end end end |