### Home Classes Methods

### In Files

- lib/v8/object.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #each
- #keys
- #method_missing
- #respond_to?
- #to_s
- #values

### Included Modules

- Enumerable

### Files

- Makefile

### Class/Module Index

Quicksearch

- V8
- V8::Access
- V8::Access::Indices
- V8::Access::Invocation
- V8::Access::Invocation::Aritize
- V8::Access::Invocation::Method
- V8::Access::Invocation::Proc
- V8::Access::Invocation::UnboundMethod
- V8::Access::Names
- V8::Array
- V8::C
- V8::Conversion
- V8::Conversion::Accessor
- V8::Conversion::Array
- V8::Conversion::Class
- V8::Conversion::Code
- V8::Conversion::Code::InvocationHandler
- V8::Conversion::Constructor
- V8::Conversion::Constructor::Args
- V8::Conversion::Fixnum
- V8::Conversion::Fundamental
- V8::Conversion::Get
- V8::Conversion::Hash
- V8::Conversion::IGet
- V8::Conversion::ISet
- V8::Conversion::Identity
- V8::Conversion::Method
- V8::Conversion::Method::MethodCache
- V8::Conversion::NativeDate
- V8::Conversion::NativeObject
- V8::Conversion::NativeString
- V8::Conversion::Object
- V8::Conversion::Primitive
- V8::Conversion::Proc
- V8::Conversion::Reference
- V8::Conversion::Set
- V8::Conversion::String
- V8::Conversion::Symbol
- V8::Conversion::Time
- V8::Error
- V8::Error::Protect
- V8::Error::Try
- V8::Function
- V8::Object
- V8::StackFrame
- V8::StackTrace
- V8::Weak
- V8::Weak::Cell
- V8::Weak::Cell::Storage
- V8::Weak::Ref
- V8::Weak::WeakValueMap
- Object
- UnboundMethod

No matching classes.

# V8::Object

### Attributes

native[R]
to_v8[R]

### Public Class Methods

new(native = nil) click to toggle source

    # File lib/v8/object.rb, line 6
    def initialize(native = nil)
      @context = V8::Context.current or fail "tried to initialize a #{self.class} without being in an entered V8::Context"
      @native = block_given? ? yield : native || V8::C::Object::New()
      @context.link self, @native
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/v8/object.rb, line 12
    def [](key)
      @context.enter do
        @context.to_ruby @native.Get(@context.to_v8(key))
      end
    end

[]=(key, value) click to toggle source

    # File lib/v8/object.rb, line 18
    def []=(key, value)
      @context.enter do
        @native.Set(@context.to_v8(key), @context.to_v8(value))
      end
      return value
    end

each() click to toggle source

    # File lib/v8/object.rb, line 39
    def each
      @context.enter do
        names = @native.GetPropertyNames()
        0.upto(names.Length() - 1) do |i|
          name = names.Get(i)
          yield @context.to_ruby(name), @context.to_ruby(@native.Get(name))
        end
      end
    end

keys() click to toggle source

    # File lib/v8/object.rb, line 25
    def keys
      @context.enter do
        names = @native.GetPropertyNames()
        0.upto( names.Length() - 1).to_enum.map {|i| @context.to_ruby names.Get(i)}
      end
    end

method_missing(name, *args, &block) click to toggle source

    # File lib/v8/object.rb, line 59
    def method_missing(name, *args, &block)
      if name.to_s =~ /(.*)=$/
        if args.length > 1
          self[$1] = args
          return args
        else
          self[$1] = args.first
          return args
        end
      end
      return super(name, *args, &block) unless self.respond_to?(name)
      property = self[name]
      if property.kind_of?(V8::Function)
        property.methodcall(self, *args)
      elsif args.empty?
        property
      else
        raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
      end
    end

respond_to?(method) click to toggle source

    # File lib/v8/object.rb, line 55
    def respond_to?(method)
      super or self[method] != nil
    end

to_s() click to toggle source

    # File lib/v8/object.rb, line 49
    def to_s
      @context.enter do
        @context.to_ruby @native.ToString()
      end
    end

values() click to toggle source

    # File lib/v8/object.rb, line 32
    def values
      @context.enter do
        names = @native.GetPropertyNames()
        0.upto( names.Length() - 1).to_enum.map {|i| @context.to_ruby @native.Get(names.Get(i))}
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.