Sha256: 09369e91ec0679dc066b385451028909ffa28e8300d131cdeab8d16838bea95c

Contents?: true

Size: 999 Bytes

Versions: 13

Compression:

Stored size: 999 Bytes

Contents

require 'corelib/module'

class Class
  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

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

  def inherited(cls)
  end

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

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
opal-0.8.1 opal/corelib/class.rb
opal-0.8.1.rc1 opal/corelib/class.rb
opal-0.8.0 opal/corelib/class.rb
opal-0.8.0.rc3 opal/corelib/class.rb
opal-0.8.0.rc2 opal/corelib/class.rb
opal-0.8.0.rc1 opal/corelib/class.rb
opal-0.8.0.beta1 opal/corelib/class.rb
opal-0.7.2 opal/corelib/class.rb
opal-0.7.1 opal/corelib/class.rb
opal-0.7.0 opal/corelib/class.rb
opal-0.7.0.rc1 opal/corelib/class.rb
opal-0.7.0.beta3 opal/corelib/class.rb
opal-0.7.0.beta2 opal/corelib/class.rb