Skip to content

Commit

Permalink
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -95,9 +95,7 @@
const_scope.constants = [];

if (id) {
klass.$$orig_scope = base;
base[id] = base.constructor[id] = klass;
base.constants.push(id);
Opal.cdecl(base, id, klass)
}
}

@@ -612,6 +610,12 @@
* constant decl
*/
Opal.cdecl = function(base_scope, name, value) {
if (value.$$is_class && value.$$orig_scope == null) {
value.$$name = name;
value.$$orig_scope = base_scope;
base_scope.constructor[name] = value;
}

base_scope.constants.push(name);
return base_scope[name] = value;
};
22 changes: 22 additions & 0 deletions spec/opal/core/language/class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe "Assigning Class.new to a constant" do
klass = Class.new do
def bar
:bar
end
end
ConstantWithAssignedClass = klass
class ConstantWithAssignedClass
def foo
:foo
end
end

it "sets the class' name" do
ConstantWithAssignedClass.name.should == 'ConstantWithAssignedClass'
end

it "can be reopened by the constant name" do
ConstantWithAssignedClass.new.foo.should == :foo
ConstantWithAssignedClass.new.bar.should == :bar
end
end

0 comments on commit d9dee02

Please sign in to comment.