Issue #12319 has been updated by Martin Drst.


Tsuyoshi Sawada wrote:
> It is confusing/surprising that something you can do with string can be done with symbol, but cannot be completely done.

It's absolutely not confusing to me that A.const_get("B::C") works, but A.const_get(:"B::C") doesn't. If at all, I'd expect it to be A.const_get(:B, :C) or A.const_get([:B, :C]). Strings can have lots of structure; Symbols essentially don't have structure.


----------------------------------------
Feature #12319: `Module#const_get` does not accept symbol with nested name
https://bugs.ruby-lang.org/issues/12319#change-58328

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
`Module#const_get` accepts non-nested string, nested string, and non-nested symbol:

~~~ruby
class A; class B; class C end end end

A.const_get("B")    # => A::B
A.const_get("B::C") # => A::B::C
A.const_get(:B)     # => A::B
~~~

but does not accept nested symbol:

~~~ruby
A.const_get(:"B::C") # => NameError: wrong constant name B::C
~~~



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>