Skip to content

Check whether a const is defined before getting it#228

Open
y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:check_const_defined
Open

Check whether a const is defined before getting it#228
y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:check_const_defined

Conversation

@y-yagi
Copy link
Copy Markdown
Contributor

@y-yagi y-yagi commented May 17, 2026

Currently, if an unexist const was specified, a namespace in an error message is URI::RFC2396_Parser.

$ ruby -w -r "uri" -e "puts URI::Mailto"
lib/uri/common.rb:57:in 'Module#const_get': uninitialized constant URI::RFC2396_Parser::Mailto (NameError)

    elsif value = RFC2396_Parser.const_get(const)

I think this is misleading a little. This PR fixes to show a correct namespace.

$ ruby -w -r "uri" -e "puts URI::Mailto"
lib/uri/common.rb:61:in 'URI.const_missing': uninitialized constant URI::Mailto (NameError)
Did you mean?  URI::MailTo

Currently, if an unexist const was specified, a namespace in an error
message is `URI::RFC2396_Parser`.

```
$ ruby -w -r "uri" -e "puts URI::Mailto"
lib/uri/common.rb:57:in 'Module#const_get': uninitialized constant URI::RFC2396_Parser::Mailto (NameError)

    elsif value = RFC2396_Parser.const_get(const)
```

I think this is misleading a little. This PR fixes to show a correct namespace.

```
$ ruby -w -r "uri" -e "puts URI::Mailto"
lib/uri/common.rb:61:in 'URI.const_missing': uninitialized constant URI::Mailto (NameError)
Did you mean?  URI::MailTo
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant