Sha256: d3d26bf2101743d0d5016509406f48399f8c4384462399a02a2ed1102da21cc4
Contents?: true
Size: 1.42 KB
Versions: 12
Compression:
Stored size: 1.42 KB
Contents
require 'corelib/module' class Class def self.new(superclass = Object, &block) %x{ if (!superclass.$$is_class) { throw Opal.TypeError.$new("superclass must be a Class"); } var alloc = Opal.boot_class_alloc(null, function(){}, superclass) var klass = Opal.setup_class_object(null, alloc, superclass.$$name, superclass.constructor); klass.$$super = superclass; klass.$$parent = superclass; // inherit scope from parent Opal.create_scope(superclass.$$scope, klass); superclass.$inherited(klass); Opal.module_initialize(klass, block); 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 def to_s %x{ var singleton_of = self.$$singleton_of; if (singleton_of && (singleton_of.$$is_class || singleton_of.$$is_module)) { return #{"#<Class:#{`singleton_of`.name}>"}; } else if (singleton_of) { // a singleton class created from an object return #{"#<Class:#<#{`singleton_of.$$class`.name}:0x#{`singleton_of.$$id`.to_s(16)}>>"}; } return #{super()}; } end end
Version data entries
12 entries across 12 versions & 1 rubygems