Project

General

Profile

Actions

Feature #10108

closed

NameError#name and nested constants

Added by robin850 (Robin Dupret) over 10 years ago. Updated over 10 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[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 !

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0