In Files
- error.c
Parent
Methods
Files
- grammar.en.rdoc
- test.ja.rdoc
- contributing.rdoc
- contributors.rdoc
- dtrace_probes.rdoc
- extension.ja.rdoc
- extension.rdoc
- globals.rdoc
- keywords.rdoc
- maintainers.rdoc
- marshal.rdoc
- regexp.rdoc
- security.rdoc
- standard_library.rdoc
- syntax.rdoc
- assignment.rdoc
- calling_methods.rdoc
- control_expressions.rdoc
- exceptions.rdoc
- literals.rdoc
- methods.rdoc
- miscellaneous.rdoc
- modules_and_classes.rdoc
- precedence.rdoc
- refinements.rdoc
- README.ja.rdoc
- README.rdoc
Class/Module Index
- ArgumentError
- Array
- BasicObject
- Bignum
- Binding
- Class
- ClosedQueueError
- Comparable
- Complex
- Complex::compatible
- ConditionVariable
- Continuation
- Data
- Dir
- ENV
- EOFError
- Encoding
- Encoding::CompatibilityError
- Encoding::Converter
- Encoding::ConverterNotFoundError
- Encoding::InvalidByteSequenceError
- Encoding::UndefinedConversionError
- EncodingError
- Enumerable
- Enumerator
- Enumerator::Generator
- Enumerator::Lazy
- Enumerator::Yielder
- Errno
- Exception
- FalseClass
- Fiber
- FiberError
- File
- File::Constants
- File::Stat
- FileTest
- Fixnum
- Float
- FloatDomainError
- GC
- GC::Profiler
- Hash
- IO
- IO::EAGAINWaitReadable
- IO::EAGAINWaitWritable
- IO::EINPROGRESSWaitReadable
- IO::EINPROGRESSWaitWritable
- IO::EWOULDBLOCKWaitReadable
- IO::EWOULDBLOCKWaitWritable
- IO::WaitReadable
- IO::WaitWritable
- IOError
- IndexError
- Integer
- Interrupt
- Kernel
- KeyError
- LoadError
- LocalJumpError
- Marshal
- MatchData
- Math
- Math::DomainError
- Method
- Module
- NameError
- NilClass
- NoMemoryError
- NoMethodError
- NotImplementedError
- Numeric
- Object
- ObjectSpace
- ObjectSpace::WeakMap
- Proc
- Process
- Process::GID
- Process::Status
- Process::Sys
- Process::UID
- Process::Waiter
- Queue
- Random
- Random::Formatter
- Range
- RangeError
- Rational
- Rational::compatible
- Regexp
- RegexpError
- RubyVM
- RubyVM::Env
- RubyVM::InstructionSequence
- RuntimeError
- ScriptError
- SecurityError
- Signal
- SignalException
- SizedQueue
- StandardError
- StopIteration
- String
- Struct
- Symbol
- SyntaxError
- SystemCallError
- SystemExit
- SystemStackError
- Thread
- Thread::Backtrace::Location
- Thread::Mutex
- ThreadError
- ThreadGroup
- Time
- TracePoint
- TrueClass
- TypeError
- UnboundMethod
- UncaughtThrowError
- ZeroDivisionError
- fatal
- unknown
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:
Fixnum.const_set :answer, 42
raises the exception:
NameError: wrong constant name answer
Public Class Methods
new(msg [, name]) → name_error
click to toggle source
Construct a new NameError exception. If given
the name parameter may subsequently be examined using the
NameError.name
method.
static VALUE name_err_initialize(int argc, VALUE *argv, VALUE self) { VALUE name; VALUE iseqw = Qnil; name = (argc > 1) ? argv[--argc] : Qnil; rb_call_super(argc, argv); rb_ivar_set(self, id_name, name); { rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); if (cfp) iseqw = rb_iseqw_new(cfp->iseq); } rb_ivar_set(self, id_iseq, iseqw); return self; }
Public Instance Methods
local_variables → array
click to toggle source
Return a list of the local variable names defined where this NameError exception was raised.
Internal use only.
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 or nil
click to toggle source
Return the name associated with this NameError exception.
static VALUE name_err_name(VALUE self) { return rb_attr_get(self, id_name); }
receiver → object
click to toggle source
Return the receiver associated with this NameError exception.
static VALUE name_err_receiver(VALUE self) { VALUE *ptr, recv, mesg; recv = rb_ivar_lookup(self, id_receiver, Qundef); if (recv != Qundef) return recv; 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"); } ptr = DATA_PTR(mesg); return ptr[NAME_ERR_MESG__RECV]; }