rails/rails — pull request #17845 by gsamokovarov (2014-11-29 11:50:48+00:00)
Title: Don't leak Object constants in core_ext/module/qualified_const

Bumped on this one recently.

Actually, I think we can remove this altogether for Rails 5. Since Ruby 2, [`Object.const_get`](http://ruby-doc.org/core-2.1.5/Module.html#method-i-const_get) actually works for qualified constant names and doesn't raises an exception for absolute paths anymore.

```ruby
>> Object.const_get '::String'
=> String
>> RUBY_VERSION
=> "2.1.4"
>> Object.const_get '::ActiveSupport::OrderedOptions'
=> ActiveSupport::OrderedOptions
```

I grepped the code and its not used anywhere but its test.

```bash
♡ ag "qualified_const_get"
activesupport/lib/active_support/core_ext/module/qualified_const.rb
26:# Object.const_get('::String') raises NameError and so does qualified_const_get.
39: def qualified_const_get(path)
52: mod = mod_name.empty? ? self : qualified_const_get(mod_name)

activesupport/test/core_ext/module/qualified_const_test.rb
59: test "qualified_const_get" do
60: assert_equal false, Object.qualified_const_get("QualifiedConstTestMod::X")
61: assert_equal false, QualifiedConstTestMod.qualified_const_get("X")
62: assert_equal 1, QualifiedConstTestMod.qualified_const_get("M::X")
63: assert_equal 1, QualifiedConstTestMod.qualified_const_get("N::X")
64: assert_equal 2, QualifiedConstTestMod.qualified_const_get("M::C::X")
66: assert_raise(NameError) { QualifiedConstTestMod.qualified_const_get("M::C::Y")}
95: assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X")}
96: assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y")}

guides/source/3_2_release_notes.md
508:* Defined new methods `Module#qualified_const_defined?`, `Module#qualified_const_get` and `Module#qualified_const_set` that are analogous to the corresponding methods in the standard API, but accept qualified constant names.

guides/source/active_support_core_extensions.md
748:The new methods are `qualified_const_defined?`, `qualified_const_get`, and
754:Object.qualified_const_get("Math::PI") # => 3.141592653589793
761:Math.qualified_const_get("E") # => 2.718281828459045
1704: mod = mod_name.empty? ? self : qualified_const_get(mod_name)
```