[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70548] [Ruby trunk - Feature #11477] NameError#qualified_name

From: eregontp@...
Date: 2015-08-22 15:05:41 UTC
List: ruby-core #70548
Issue #11477 has been updated by Benoit Daloze.


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

----------------------------------------
Feature #11477: NameError#qualified_name
https://bugs.ruby-lang.org/issues/11477#change-53955

* Author: Yuki Nishijima
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
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](https://github.com/rails/rails/blob/ebe73abea0ae02094ddc28f8fd60ae92373b6113/activesupport/lib/active_support/core_ext/name_error.rb#L2-L14). This will allow gems like Rails and did_you_mean to get a qualified name without parsing an error message.

```ruby
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`:

```ruby
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



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

In This Thread

Prev Next