class NameError
Raised when a given name is invalid or undefined.
puts foo
raises the exception:
NameError: undefined local variable or method `foo' for main:Object
Since constant names must start with a capital:
Integer.const_set :answer, 42
raises the exception:
NameError: wrong constant name answer
Public Class Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/errors.rbs, line 275
def initialize: (?string msg, ?String? name, ?receiver: T?) -> void
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:
[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]
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/errors.rbs, line 286
def local_variables: () -> ::Array[Symbol]
Return a list of the local variable names defined where this NameError exception was raised.
Internal use only.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/errors.rbs, line 294
def name: () -> String?
Return the name associated with this NameError exception.