Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

NameError.new

[T] (?::string msg, ?::String? name, ?receiver: T?) -> ::NameError[T]
NameError.new(msg=nil, name=nil, receiver: nil) → name_error

Construct a new NameError exception. If given the name parameter may subsequently be examined using the NameError#name method. receiver parameter allows to pass object in context of which the error happened. Example:

Example
[1, 2, 3].method(:rject) # NameError with name "rject" and receiver: Array
[1, 2, 3].singleton_method(:rject) # NameError with name "rject" and receiver: [1, 2, 3]
See also #local_variables #name also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0