Class: Class

Inherits:
Object show all
Defined in:
opal/opal/corelib/class.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(sup = Object, &block) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'opal/opal/corelib/class.rb', line 4

def self.new(sup = Object, &block)
  %x{
    if (!sup.$$is_class) {
      #{raise TypeError, "superclass must be a Class"};
    }

    function AnonClass(){};
    var klass        = Opal.boot_class(sup, AnonClass)
    klass.$$name     = nil;
    klass.$$parent   = sup;
    klass.$$is_class = true;

    // inherit scope from parent
    Opal.create_scope(sup.$$scope, klass);

    sup.$inherited(klass);

    if (block !== nil) {
      var block_self = block.$$s;
      block.$$s = null;
      block.call(klass);
      block.$$s = block_self;
    }

    return klass;
  }
end

Instance Method Details

#allocateObject


32
33
34
35
36
37
38
# File 'opal/opal/corelib/class.rb', line 32

def allocate
  %x{
    var obj = new self.$$alloc();
    obj.$$id = Opal.uid();
    return obj;
  }
end

#inherited(cls) ⇒ Object


40
41
# File 'opal/opal/corelib/class.rb', line 40

def inherited(cls)
end

#new(*args, &block) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'opal/opal/corelib/class.rb', line 43

def new(*args, &block)
  %x{
    var obj = #{allocate};

    obj.$initialize.$$p = block;
    obj.$initialize.apply(obj, args);
    return obj;
  }
end

#superclassObject


53
54
55
# File 'opal/opal/corelib/class.rb', line 53

def superclass
  `self.$$super || nil`
end