Exception: NameError
- Inherits:
-
StandardError
- Object
- Exception
- StandardError
- NameError
- Defined in:
- error.c,
error.c
Overview
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:
Fixnum.const_set :answer, 42
raises the exception:
NameError: wrong constant name answer
Direct Known Subclasses
Defined Under Namespace
Classes: message
Instance Method Summary collapse
-
#new(msg[, name]) ⇒ Object
constructor
Construct a new NameError exception.
-
#name ⇒ String?
Return the name associated with this NameError exception.
Methods inherited from Exception
#==, #backtrace, #backtrace_locations, #cause, #exception, exception, #inspect, #message, #set_backtrace, #to_s
Constructor Details
#new(msg[, name]) ⇒ Object
Construct a new NameError exception. If given the name parameter may subsequently be examined using the NameError.name
method.
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 |
# File 'error.c', line 1005
static VALUE
name_err_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE name;
name = (argc > 1) ? argv[--argc] : Qnil;
rb_call_super(argc, argv);
rb_iv_set(self, "name", name);
return self;
}
|
Instance Method Details
#name ⇒ String?
Return the name associated with this NameError exception.
1023 1024 1025 1026 1027 |
# File 'error.c', line 1023
static VALUE
name_err_name(VALUE self)
{
return rb_attr_get(self, rb_intern("name"));
}
|