Movatterモバイル変換


[0]ホーム

URL:


HomeClassesMethods

In Files

  • vm.c

Parent

Object

Methods

Files

Class/Module Index[+]

Quicksearch
No matching classes.

Thread::Backtrace::Location

An object representation of a stack frame, initialized byKernel#caller_locations.

For example:

# caller_locations.rbdefa(skip)caller_locations(skip)enddefb(skip)a(skip)enddefc(skip)b(skip)endc(0..2).mapdo|call|putscall.to_send

Runningruby caller_locations.rb will produce:

caller_locations.rb:2:in `a'caller_locations.rb:5:in `b'caller_locations.rb:8:in `c'

Here's another example with a slightly different result:

# foo.rbclassFooattr_accessor :locationsdefinitialize(skip)@locations =caller_locations(skip)endendFoo.new(0..2).locations.mapdo|call|putscall.to_send

Now runruby foo.rb and you should see:

init.rb:4:in `initialize'init.rb:8:in `new'init.rb:8:in `<main>'

Public Instance Methods

absolute_path()click to toggle source

Returns the full file path of this frame.

Same aspath, except that it willreturn absolute path even if the frame is in the main script.

                static VALUElocation_absolute_path_m(VALUE self){    return location_realpath(location_ptr(self));}
base_label()click to toggle source

Returns the base label of this frame.

Usually same aslabel, withoutdecoration.

                static VALUElocation_base_label_m(VALUE self){    return location_base_label(location_ptr(self));}
inspect()click to toggle source

Returns the same as callinginspect on the stringrepresentation of to_str

                static VALUElocation_inspect_m(VALUE self){    return rb_str_inspect(location_to_str(location_ptr(self)));}
label()click to toggle source

Returns the label of this frame.

Usually consists of method, class, module, etc names with decoration.

Consider the following example:

deffooputscaller_locations(0).first.label1.timesdoputscaller_locations(0).first.label1.timesdoputscaller_locations(0).first.labelendendend

The result of callingfoo is this:

label: foolabel: block in foolabel: block (2 levels) in foo
                static VALUElocation_label_m(VALUE self){    return location_label(location_ptr(self));}
lineno()click to toggle source

Returns the line number of this frame.

For example, usingcaller_locations.rb fromThread::Backtrace::Location

loc =c(0..1).firstloc.lineno#=> 2
                static VALUElocation_lineno_m(VALUE self){    return INT2FIX(location_lineno(location_ptr(self)));}
path()click to toggle source

Returns the file name of this frame. This will generally be an absolutepath, unless the frame is in the main script, in which case it will be thescript location passed on the command line.

For example, usingcaller_locations.rb fromThread::Backtrace::Location

loc =c(0..1).firstloc.path#=> caller_locations.rb
                static VALUElocation_path_m(VALUE self){    return location_path(location_ptr(self));}
to_s()click to toggle source

Returns aKernel#callerstyle string representing this frame.

                static VALUElocation_to_str_m(VALUE self){    return location_to_str(location_ptr(self));}

This page was generated for Ruby 3.0.0

Generated with Ruby-doc Rdoc Generator 0.42.0.


[8]ページ先頭

©2009-2025 Movatter.jp