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
Class Methods
3.1
View on GitHub
static VALUE
name_err_initialize(int argc, VALUE *argv, VALUE self)
{
ID keywords[1];
VALUE values[numberof(keywords)], name, options;
argc = rb_scan_args(argc, argv, "*:", NULL, &options);
keywords[0] = id_receiver;
rb_get_kwargs(options, keywords, 0, numberof(values), values);
name = (argc > 1) ? argv[--argc] : Qnil;
rb_call_super(argc, argv);
name_err_init_attr(self, values[0], name);
return self;
}
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]
Instance Methods