るりまサーチ

最速Rubyリファレンスマニュアル検索!
5件ヒット [1-5件を表示] (0.387秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:l[x] > クエリ:const_source_location[x]

別のキーワード

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

ライブラリ

クラス

検索結果

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

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

...号を配列で返します。

@param name Symbol,String で定数の名前を指定します。
@param inherited true を指定するとスーパークラスや include したモジュールで定義された定数が対象にはなります。false を指定した場合 対象にはなりませ...
...nil を返します。
定数は見つかったがソースファイルが見つからなかった場合は空の配列を返します。

//emlist[例][ruby]{
# test.rb:
class A # line 1
C1 = 1
C2 = 2
end

module M # line 6
C3 = 3
end

class B < A # line 10
includ...
...class A # 継続して A を定義する
C2 = 8 # 定数を再定義する
end

p B.const_source_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('C...