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.$$is_class || sup.$$is_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