Project

General

Profile

Feature #10108

NameError#name and nested constants

Added by Robin Dupret almost 2 years ago. Updated almost 2 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
[ruby-core:64175]

Description

Hello,

We wanted to bring a discussion around the behavior of NameError#name with nested constants. The result can be quite unexpected when we are dealing with them. For instance:

begin
  Math::PHI
rescue NameError => e
  e.name # => :PHI
end

Having Math::PHI seems more expected. Rubinius works the same way as MRI while JRuby will return a symbol with the full path (i.e. :"Math::PHI"). Is there any reason why you are returning only the last part of the missing "path" ? At the very least, there is a documentation problem since NameError#name's documentation states:

name_error.name    ->  string or nil

but it always return a symbol.

Have a nice day !

History

#1 [ruby-core:64176] Updated by Nobuyoshi Nakada almost 2 years ago

  • Tracker changed from Misc to Feature
  • Description updated (diff)

Do you want a method to return full qualified name, or an array of names?

#2 [ruby-core:64177] Updated by Vipul Amler almost 2 years ago

A full qualified name would be a more appropriate and natural fit.

#3 [ruby-core:64199] Updated by Robin Dupret almost 2 years ago

Yes, a full qualified name seems more appropriate and more consistent with the output of the error message. Thanks for the quick answer !

#4 [ruby-core:64287] Updated by Nobuyoshi Nakada almost 2 years ago

  • Status changed from Open to Feedback

Good name is desired, as usual.

Also available in: Atom PDF