Skip to content

Commit 5913b8d

Browse files
committedSep 1, 2014
Refactor Kernel#singleton_class
Removed dead branches, removed duplication.
1 parent fc841f1 commit 5913b8d

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed
 

‎opal/corelib/kernel.rb

+8-19
Original file line numberDiff line numberDiff line change
@@ -512,32 +512,22 @@ def respond_to?(name, include_all = false)
512512

513513
def singleton_class
514514
%x{
515-
if (self._isClass) {
516-
if (self.__meta__) {
517-
return self.__meta__;
518-
}
515+
if (self.__meta__) {
516+
return self.__meta__;
517+
}
519518
519+
if (self._isClass) {
520520
var meta = new $opal.Class._alloc;
521521
meta._klass = $opal.Class;
522-
self.__meta__ = meta;
522+
523523
// FIXME - is this right? (probably - methods defined on
524524
// class' singleton should also go to subclasses?)
525525
meta._proto = self.constructor.prototype;
526+
526527
meta._isSingleton = true;
527528
meta.__inc__ = [];
528529
meta._methods = [];
529-
530530
meta._scope = self._scope;
531-
532-
return meta;
533-
}
534-
535-
if (self._isClass) {
536-
return self._klass;
537-
}
538-
539-
if (self.__meta__) {
540-
return self.__meta__;
541531
}
542532
543533
else {
@@ -549,13 +539,12 @@ def singleton_class
549539
meta._name = class_id;
550540
551541
meta._proto = self;
552-
self.__meta__ = meta;
553542
meta._klass = orig_class._klass;
554543
meta._scope = orig_class._scope;
555544
meta.__parent = orig_class;
556-
557-
return meta;
558545
}
546+
547+
return self.__meta__ = meta;
559548
}
560549
end
561550

0 commit comments

Comments
 (0)
Please sign in to comment.