Skip to content
On this page

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

class · Ruby 3.1

NameError

< StandardError 3 instance methods 1 class methods

Raised when a given name is invalid or undefined.

Example
puts foo

raises the exception:

NameError: undefined local variable or method `foo' for main:Object

Since constant names must start with a capital:

Example
Integer.const_set :answer, 42

raises the exception:

NameError: wrong constant name answer

Class methods 1

Instance methods 3