Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

NameError.new

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.4 · 3.3 · 3.2 · 3.0