Skip to content

Commit

Permalink
RE: jruby#2635 Fix support of const_get with leading colons
Browse files Browse the repository at this point in the history
  • Loading branch information
arlandism authored and kares committed Apr 16, 2015
1 parent edce1da commit 08edd82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -3039,7 +3039,10 @@ public IRubyObject const_get_2_0(ThreadContext context, IRubyObject[] args) {

RubyModule mod = this;

if (symbol.startsWith("::")) mod = runtime.getObject();
if (symbol.startsWith("::")) {
mod = runtime.getObject();
symbol = symbol.substring(2);
}

int sep;
while((sep = symbol.indexOf("::")) != -1) {
Expand Down
19 changes: 19 additions & 0 deletions spec/regression/GH-2635_const_get_with_leading_colons_spec.rb
@@ -0,0 +1,19 @@
describe ".const_get" do

module Example
class Foo
Bar = "bar"
end
end

context "with leading colons" do
it "finds the toplevel constant" do
Object.const_get("::Example").should == Example
end

it "works with arbitrarily nested constants" do
Object.const_get("::Example::Foo::Bar").should == "bar"
end
end

end

0 comments on commit 08edd82

Please sign in to comment.