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



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

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



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

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

#inherited(cls) ⇒ Object



37
38
# File 'opal/opal/corelib/class.rb', line 37

def inherited(cls)
end

#new(*args, &block) ⇒ Object



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

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

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

#superclassObject



50
51
52
# File 'opal/opal/corelib/class.rb', line 50

def superclass
  `self._super || nil`
end