るりまサーチ

最速Rubyリファレンスマニュアル検索!
197件ヒット [1-100件を表示] (0.238秒)
トップページ > クエリ:_builtin[x] > クエリ:Location[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Thread::Backtrace::Location (26000.0)

Ruby のフレームを表すクラスです。

...er_locations から生成されます。

//emlist[例1][ruby]{
# caller_locations.rb
def a(skip)
caller_locations(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end

c(0..2).map do |call|
puts call.to_s
end
//}

例1の実行結果:

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

//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
puts call.to_s
end
//}

例2の実行結果:

init.rb:4:in `initialize'...

Kernel.#caller_locations(range) -> [Thread::Backtrace::Location] | nil (14224.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@pa...
...uby]{
def test1(start, length)
location
s = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations # => []
test3(1, nil)
# =>...
...(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}

@see Thread::Backtrace::Location, Kernel.#caller...

Kernel.#caller_locations(start = 1, length = nil) -> [Thread::Backtrace::Location] | nil (14224.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@pa...
...uby]{
def test1(start, length)
location
s = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations # => []
test3(1, nil)
# =>...
...(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}

@see Thread::Backtrace::Location, Kernel.#caller...

Thread#backtrace_locations(range) -> [Thread::Backtrace::Location] | nil (14224.0)

スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。

...スレッドの現在のバックトレースを Thread::Backtrace::Location の配
列で返します。

引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。

@param start 開始フレームの位置を数値で指定します...
...オブジェクトを指定します。

Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。

//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_locations # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test...
....rb:1:in `block in <main>'"]
//}

@see Thread::Backtrace::Location...

Thread#backtrace_locations(start = 0, length = nil) -> [Thread::Backtrace::Location] | nil (14224.0)

スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。

...スレッドの現在のバックトレースを Thread::Backtrace::Location の配
列で返します。

引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。

@param start 開始フレームの位置を数値で指定します...
...オブジェクトを指定します。

Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。

//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_locations # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test...
....rb:1:in `block in <main>'"]
//}

@see Thread::Backtrace::Location...

絞り込み条件を変える

Exception#backtrace_locations -> [Thread::Backtrace::Location] (14217.0)

バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。

...バックトレース情報を返します。Exception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。

現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。

//emlist[例: test.rb][ruby]{
require...
...ong month"
end

def get_exception
return begin
yield
rescue => e
e
end
end

e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
//}

@see...

Module#const_source_location(name, inherited = true) -> [String, Integer] (14167.0)

name で指定した定数の定義を含むソースコードのファイル名と行番号を配列で返します。

...location('C4') # => ["test.rb", 12]
p B.const_source_location('C3') # => ["test.rb", 7]
p B.const_source_location('C1') # => ["test.rb", 2]

p B.const_source_location('C3', false) # => nil -- include したモジュールは検索しない

p A.const_source_location...
...Object.const_source_location('B') # => ["test.rb", 10] -- Object はトップレベルの定数を検索する
p Object.const_source_location('A') # => ["test.rb", 1] -- クラスが再定義された場合は最初の定義位置を返す

p B.const_source_location('A') # =>...
...p M.const_source_location('A') # => ["test.rb", 1] -- Object は継承していないが追加で modules をチェックする

p Object.const_source_location('A::C1') # => ["test.rb", 2] -- ネストの指定もサポートしている
p Object.const_source_location('String') # =>...

Proc#source_location -> [String, Integer] | nil (14131.0)

ソースコードのファイル名と行番号を配列で返します。

...by]{
# /path/to/target.rb を実行
proc {}.source_location # => ["/path/to/target.rb", 1]
proc {}.source_location # => ["/path/to/target.rb", 2]
(eval "proc {}").source_location # => ["(eval)", 1]
method(:p).to_proc.source_location # => nil
//}

@see Method#source_location...

UnboundMethod#source_location -> [String, Integer] | nil (14125.0)

ソースコードのファイル名と行番号を配列で返します。

...nil を返します。

//emlist[例][ruby]{
require 'time'

Time.instance_method(:zone).source_location # => nil
Time.instance_method(:httpdate).source_location # => ["/Users/user/.rbenv/versions/2.4.3/lib/ruby/2.4.0/time.rb", 654]
//}

@see Proc#source_location, Method#source_location...

Method#source_location -> [String, Integer] | nil (14119.0)

ソースコードのファイル名と行番号を配列で返します。

...@see Proc#source_location

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
def foo; end
end
# ----- end of /tmp/foo.rb ----

require '/tmp/foo'

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
m.source_location # => ["/tmp/foo.rb", 2]

method(:puts).source_location # => nil
//}...

絞り込み条件を変える

<< 1 2 > >>