Class: Mustang::V8::Number

Inherits:
Primitive show all
Includes:
Comparable, Delegated
Defined in:
lib/mustang/v8/number.rb,
ext/v8/v8_number.cpp

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegated

#method_missing, #old_method_missing, #old_respond_to?, #respond_to?, #to_s

Methods inherited from Value

#==, #===, #array?, #ary?, #bool?, #boolean?, #date?, #empty?, #external?, #false?, #func?, #function?, #int?, #integer?, #null?, #num?, #number?, #obj?, #object?, #regex?, #regexp?, #str?, #string?, #to_boolean, #to_integer, #to_number, #to_object, #to_string, #true?, #undefined?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Delegated

Class Method Details

.V8::Number.new(float) ⇒ Object

Returns new V8 number reflected from given float value.



28
29
30
31
32
33
34
# File 'ext/v8/v8_number.cpp', line 28

static VALUE rb_v8_number_new(VALUE klass, VALUE data)
{
  HandleScope scope;
  PREVENT_CREATION_WITHOUT_CONTEXT();
  VALUE num = rb_funcall2(data, rb_intern("to_f"), 0, NULL);
  return v8_ref_new(klass, to_v8_number(num));
}

Instance Method Details

#<=>(other) ⇒ Object



7
8
9
# File 'lib/mustang/v8/number.rb', line 7

def <=>(other)
  to_f <=> other
end

#delegateObject



11
12
13
# File 'lib/mustang/v8/number.rb', line 11

def delegate
  to_f
end

#to_fObject

Returns float value representation of referenced v8 number.



43
44
45
46
47
# File 'ext/v8/v8_number.cpp', line 43

static VALUE rb_v8_number_to_f(VALUE self)
{
  HandleScope scope;
  return rb_float_new(unwrap(self)->NumberValue());
}