Class: Class

Inherits:
Object
  • 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
# File 'opal/opal/corelib/class.rb', line 4

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

    function AnonClass(){};
    var klass       = Opal.boot(sup, AnonClass)
    klass._name     = nil;
    klass.__parent  = sup;

    // 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



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

def allocate
  %x{
    var obj = new self._alloc;
    obj._id = Opal.uid();
    return obj;
  }
end

#inherited(cls) ⇒ Object



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

def inherited(cls)
end

#new(*args, &block) ⇒ Object



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

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

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

#superclassObject



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

def superclass
  `self._super || nil`
end