Skip to content

Commit

Permalink
Fix constant name regex in Module methods
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 8, 2013
1 parent 050f137 commit c7a7047
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions corelib/module.rb
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit c7a7047

Please sign in to comment.