Skip to content

Commit

Permalink
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions corelib/module.rb
Original file line number Diff line number Diff line change
@@ -198,7 +198,8 @@ def constants
# check for constant within current scope
# if inherit is true or self is Object, will also check ancestors
def const_defined?(name, inherit = true)
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w+$/
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w*$/

%x{
scopes = [#{self}._scope];
if (inherit || #{self} === Opal.Object) {
@@ -222,7 +223,8 @@ def const_defined?(name, inherit = true)
# check for constant within current scope
# if inherit is true or self is Object, will also check ancestors
def const_get(name, inherit = true)
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w+$/
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w*$/

%x{
var scopes = [#{self}._scope];
if (inherit || #{self} == Opal.Object) {
@@ -245,11 +247,13 @@ def const_get(name, inherit = true)

def const_missing(const)
name = `#{self}._name`

raise NameError, "uninitialized constant #{name}::#{const}"
end

def const_set(name, value)
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w+$/
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w*$/

begin
name = name.to_str
rescue

0 comments on commit c7a7047

Please sign in to comment.