Skip to content

Commit

Permalink
Invoke Module#const_set before Class#inherited (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbiedermann authored and iliabylich committed Jun 4, 2018
1 parent 1976f66 commit 9e5e9ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions opal/corelib/runtime.js
Expand Up @@ -502,17 +502,17 @@
if (bridged) {
Opal.bridge(bridged);
klass = bridged;
Opal.const_set(scope, name, klass);
} else {
// Create the class object (instance of Class)
klass = Opal.allocate_class(name, superclass, constructor);
Opal.const_set(scope, name, klass);
// Call .inherited() hook with new class on the superclass
if (superclass.$inherited) {
superclass.$inherited(klass);
}
}

Opal.const_set(scope, name, klass);

return klass;

}
Expand Down
18 changes: 18 additions & 0 deletions spec/opal/core/class/inherited.rb
@@ -0,0 +1,18 @@
module ModuleInheritedTestModule
class A
def self.inherited(subclass)
$ScratchPad << subclass.name
end
end
end

describe 'Class#inherited' do
it 'gets called after setting a base scope of the subclass' do
$ScratchPad = []
module ModuleInheritedTestModule
class B < A
end
end
$ScratchPad.should == ['ModuleInheritedTestModule::B']
end
end

0 comments on commit 9e5e9ba

Please sign in to comment.