るりまサーチ

最速Rubyリファレンスマニュアル検索!
18件ヒット [1-18件を表示] (0.294秒)
トップページ > クエリ:Class[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] (18185.0)

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

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

module M # line 6
C3 = 3
end

class
B < A # line 10
include M
C4 = 4
end

class
A # 継続して A を定義する
C2 = 8 # 定数を再定義する
end

p B.const_source_location('C4') # => ["te...
...const_source_location('C1') # => ["test.rb", 2]

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

p A.const_source_location('C2') # => ["test.rb", 16] -- 最後に定義された位置を返す

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

p B.const_source_location('A') # => ["test.rb", 1] -- Object を継承している為
p M.const_source_location('A') # => ["t...

NEWS for Ruby 2.7.0 (42.0)

NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ted です。 15575
この警告は「-W:no-deprecated」オプションで止められます。

//emlist{
def foo
class
<< Object.new
yield #=> warning: `yield' in class syntax will not be supported from Ruby 3.0. 15575
end
end
foo { p :ok }
//}

* 引数を転送する記法「(...)...
...sday?) #=> next Tuesday
//}
//emlist[Enumerator::Lazy#eager][ruby]{
a = %w(foo bar baz)
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
p e.class #=> Enumerator
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
//}
//emlist[Enumerator::Lazy#with_index][ruby]{
("a"..).lazy...
...てくる情報が増えました。 14145

* Module
* 新規メソッド
* 定数が定義された場所を取得するModule#const_source_location
メソッドが追加されました。 10771
* 通常の引数分解でキーワード引数を渡すようにメソッド...