Project

General

Profile

Actions

Feature #11477

closed

NameError#qualified_name

Feature #11477: NameError#qualified_name

Added by yuki24 (Yuki Nishijima) about 10 years ago. Updated almost 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

Hi,

This is a followup issue to #11252. I'd like to add a method that basically does the same thing as NameError#missing_name. This will allow gems like Rails and did_you_mean to get a qualified name without parsing an error message.

begin
  HelloWorld
rescue NameError => e
  error.name           # => :HelloWorld
  error.qualified_name # => :HelloWorld
end

begin
  String::DoesntExist
rescue NameError => e
  error.name           # => :DoesntExist
  error.qualified_name # => :"String::DoesntExist"
end

I'm not actually sure what it should return when the module/class is an anonymous module/class, but one thing we can do is just use the result of #to_s:

m = Module.new

begin
  m::DoesntExist
rescue NameError => e
  error.name           # => :DoesntExist
  error.qualified_name # => :"#<Module:0x0000000260c2f8>::DoesntExist"
end

I'm open to suggestions. Let me know what you think.

Yuki

Updated by Eregon (Benoit Daloze) about 10 years ago Actions #1

Is NameError#receiver (#10881) not enough and better/easier to use?

Updated by Eregon (Benoit Daloze) about 10 years ago Actions #2

To clarify, make it so that NameError#receiver returns the receiving module in a "uninitialized constant" NameError.

Updated by yuki24 (Yuki Nishijima) about 10 years ago Actions #3

That actually makes more sense and is what we talked about at the last Ruby developers meeting. According to Nobu it requires a lot of work, though. But in terms of the interface, I'm 👍 on NameError#receiver returning the receiving module in a "uninitialized constant" NameError.

Updated by yuki24 (Yuki Nishijima) almost 10 years ago Actions #4 [ruby-core:71494]

  • Status changed from Open to Closed

Since #11252 is completely done and NameError#receiver now returns the receiving module in a "uninitialized constant" NameError, I'll close this issue.

Actions

Also available in: PDF Atom