Exception: NameError
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
::StandardError,
::Exception
|
|
|
Instance Chain:
self,
::StandardError,
::Exception
|
|
| Inherits: |
StandardError
|
| Defined in: | error.c, error.c |
Overview
Class Attribute Summary
::Exception - Inherited
| .to_tty? | Returns |
Class Method Summary
-
.new(msg = nil, name = nil, receiver: nil) ⇒ name_error
constructor
Construct a new
NameErrorexception.
::Exception - Inherited
| .exception | Returns an exception object of the same class as |
| .new | Returns a new exception object. |
Instance Method Summary
-
#local_variables ⇒ Array
Return a list of the local variable names defined where this
NameErrorexception was raised. -
#name ⇒ String?
Return the name associated with this
NameErrorexception. -
#receiver ⇒ Object
Return the receiver associated with this
NameErrorexception.
::Exception - Inherited
| #== | Returns whether |
| #backtrace | Returns the backtrace (the list of code locations that led to the exception), as an array of strings. |
| #backtrace_locations | Returns the backtrace (the list of code locations that led to the exception), as an array of |
| #cause | Returns the previous value of global variable |
| #detailed_message | Returns the message string with enhancements: |
| #exception | Returns an exception object of the same class as |
| #full_message | Returns an enhanced message string: |
| #inspect | Returns a string representation of |
| #message | Returns |
| #set_backtrace | Sets the backtrace value for |
| #to_s | Returns a string representation of |
Constructor Details
.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 #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]
# File 'error.c', line 2400
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;
}
Instance Method Details
#local_variables ⇒ Array
Return a list of the local variable names defined where this NameError exception was raised.
Internal use only.
# File 'error.c', line 2454
static VALUE
name_err_local_variables(VALUE self)
{
VALUE vars = rb_attr_get(self, id_local_variables);
if (NIL_P(vars)) {
VALUE iseqw = rb_attr_get(self, id_iseq);
if (!NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
if (NIL_P(vars)) vars = rb_ary_new();
rb_ivar_set(self, id_local_variables, vars);
}
return vars;
}
#name ⇒ String?
Return the name associated with this NameError exception.
# File 'error.c', line 2438
static VALUE
name_err_name(VALUE self)
{
return rb_attr_get(self, id_name);
}
#receiver ⇒ Object
Return the receiver associated with this NameError exception.
# File 'error.c', line 2739
static VALUE
name_err_receiver(VALUE self)
{
VALUE recv = rb_ivar_lookup(self, id_recv, Qundef);
if (!UNDEF_P(recv)) return recv;
VALUE mesg = rb_attr_get(self, id_mesg);
if (!rb_typeddata_is_kind_of(mesg, &name_err_mesg_data_type)) {
rb_raise(rb_eArgError, "no receiver is available");
}
name_error_message_t *ptr;
TypedData_Get_Struct(mesg, name_error_message_t, &name_err_mesg_data_type, ptr);
return ptr->recv;
}