るりまサーチ

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

別のキーワード

  1. rss source
  2. _builtin source_location
  3. _builtin source_encoding
  4. socket ip_block_source
  5. socket mcast_block_source

ライブラリ

クラス

キーワード

検索結果

Method#source_location -> [String, Integer] | nil (18137.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
//}...

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

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

...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') # => ["test.rb", 12]
p B.const_source_location('C3')...
...st_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('B...
...検索する
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') # => ["test...

NEWS for Ruby 2.7.0 (240.0)

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

...p b #=> 1
p c #=> [2, 3]
end

//}

//emlist[][ruby]{
case {a: 0, b: 1}
in {a: 0, x: 1}
:unreachable
in {a: 0, b: var}
p var #=> 1
end

//}

//emlist[][ruby]{
case -1
in 0 then :unreachable
in 1 then :unreachable
end
#=> NoMatchingPatternError
//}

//emlist{
json = <<END
{
"name": "Alice",
"a...
...ge": 30,
"children": [{ "name": "Bob", "age": 2 }]
}
END


JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: name, age: age}]}

p name #=> "Bob"
p age #=> 2

JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: "Charlie", age: age}]}
#=> NoMatchin...
...くる情報が増えました。 14145

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

Method#inspect -> String (84.0)

self を読みやすい文字列として返します。

...数を表します。
「foo.rb:2」は Method#source_location を表します。
source_location
が nil の場合には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end

end

class Bar
include Foo
def bar(a, b)
end

end


p Bar.new.method(:foo) # => #<Method: B...
...ef foo
end

end

p obj.method(:foo) # => #<Method: "".foo() foo.rb:4>

# クラスメソッド(クラスの特異メソッド)
class Foo
def Foo.foo
end

end

p Foo.method(:foo) # => #<Method: Foo.foo() foo.rb:11>

# スーパークラスのクラスメソッド
class Bar < Foo
end

p Bar...
....method(:foo) # => #<Method: Bar(Foo).foo() foo.rb:11>

# 以下は(形式1)の出力になる
module Baz
def baz
end

end


class <<obj
include Baz
end

p obj.method(:baz) # => #<Method: String(Baz)#baz() foo.rb:23>
//}

@see Object#inspect...

Method#to_s -> String (84.0)

self を読みやすい文字列として返します。

...数を表します。
「foo.rb:2」は Method#source_location を表します。
source_location
が nil の場合には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end

end

class Bar
include Foo
def bar(a, b)
end

end


p Bar.new.method(:foo) # => #<Method: B...
...ef foo
end

end

p obj.method(:foo) # => #<Method: "".foo() foo.rb:4>

# クラスメソッド(クラスの特異メソッド)
class Foo
def Foo.foo
end

end

p Foo.method(:foo) # => #<Method: Foo.foo() foo.rb:11>

# スーパークラスのクラスメソッド
class Bar < Foo
end

p Bar...
....method(:foo) # => #<Method: Bar(Foo).foo() foo.rb:11>

# 以下は(形式1)の出力になる
module Baz
def baz
end

end


class <<obj
include Baz
end

p obj.method(:baz) # => #<Method: String(Baz)#baz() foo.rb:23>
//}

@see Object#inspect...

絞り込み条件を変える