種類
- インスタンスメソッド (275)
- 特異メソッド (22)
- クラス (11)
クラス
- BasicObject (22)
- IO (198)
- Module (44)
- TracePoint (33)
キーワード
- TracePoint (11)
-
class
_ eval (22) - each (66)
-
each
_ line (66) -
instance
_ eval (22) - lineno= (11)
-
module
_ eval (22) - reopen (33)
- rewind (11)
- trace (11)
検索結果
先頭5件
-
IO
# lineno -> Integer (26127.0) -
現在の行番号を整数で返します。実際には IO#gets が呼ばれた回数です。 改行以外のセパレータで gets が呼ばれた場合など、実際の行番号と異なる場合があります。
...にオープンされていなければ発生します。
f = File.new("testfile")
f.lineno #=> 0
f.gets #=> "This is line one\n"
f.lineno #=> 1
f.gets #=> "This is line two\n"
f.lineno #=> 2
@see $.... -
TracePoint
. new(*events) {|obj| . . . } -> TracePoint (26121.0) -
新しい TracePoint オブジェクトを作成して返します。トレースを有効 にするには TracePoint#enable を実行してください。
...にするには TracePoint#enable を実行してください。
//emlist[例:irb で実行した場合][ruby]{
trace = TracePoint.new(:call) do |tp|
p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
end
# => #<TracePoint:0x007f17372cdb20>
trace.enable
# => false
puts "Hello, TracePoin......ソッ
ドを実行した場合には RuntimeError が発生します。
//emlist[例][ruby]{
TracePoint.trace(:line) do |tp|
$tp = tp
end
$tp.lineno # => access from outside (RuntimeError)
//}
他のスレッドから参照する事も禁じられています。
@raise ThreadError ブロック......ソッ
ドを実行した場合には RuntimeError が発生します。
//emlist[例][ruby]{
TracePoint.trace(:line) do |tp|
$tp = tp
end
$tp.lineno # => access from outside (RuntimeError)
//}
他のスレッドから参照する事も禁じられています。
@raise ArgumentError ブロッ... -
TracePoint
# lineno -> Integer (26115.0) -
発生したイベントの行番号を返します。
...発生したイベントの行番号を返します。
@raise RuntimeError イベントフックの外側で実行した場合に発生します。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call, :return) do |tp|
tp.lineno
end
trace.enable
foo 1
# => 1
# 3
//}... -
IO
# lineno=(number) (14121.0) -
現在の行番号を number にセットします。 $. は次回の読み込みの時に更新されます。
...み込み用にオープンされていなければ発生します。
f = File.new("testfile")
f.gets #=> "This is line one\n"
$. #=> 1
f.lineno = 1000
f.lineno #=> 1000
$. #=> 1
f.gets... -
Module
# class _ eval(expr , fname = "(eval)" , lineno = 1) -> object (8128.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...行されます。
スタックトレースの表示などを差し替えることができます。
@param lineno 文字列を指定します。行番号 lineno から文字列 expr が書かれているかのように実行されます。
スタックトレースの表......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
Module
# module _ eval(expr , fname = "(eval)" , lineno = 1) -> object (8128.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...行されます。
スタックトレースの表示などを差し替えることができます。
@param lineno 文字列を指定します。行番号 lineno から文字列 expr が書かれているかのように実行されます。
スタックトレースの表......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
BasicObject
# instance _ eval(expr , filename = "(eval)" , lineno = 1) -> object (8127.0) -
オブジェクトのコンテキストで文字列 expr またはオブジェクト自身をブロックパラメータとするブロックを 評価してその結果を返します。
...行されます。スタックトレースの
表示などを差し替えることができます。
@param lineno 整数を指定します。行番号 lineno から文字列 expr が書かれているかのように実行されます。
スタックトレースの表......ます。
//emlist[例][ruby]{
class Foo
def initialize data
@key = data
end
private
def do_fuga
p 'secret'
end
end
some = Foo.new 'XXX'
some.instance_eval{p @key} #=> "XXX"
some.instance_eval{do_fuga } #=> "secret" # private メソッドも呼び出せる
some.instance_eval 'ra......imeError)
//}
//emlist[例][ruby]{
class Bar < BasicObject
def call1
instance_eval("::ENV.class")
end
def call2
instance_eval("ENV.class")
end
end
bar = Bar.new
bar.call1 # => Object
bar.call2 # raise NameError
//}
@see Module#module_eval, Kernel.#eval, BasicObject#instance_exec... -
IO
# each(limit , chomp: false) -> Enumerator (8038.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...: 引数なし][ruby]{
IO.write("testfile", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//e......10 を指定][ruby]{
IO.write("testfile", "This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: A......omp = true][ruby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see... -
IO
# each(limit , chomp: false) {|line| . . . } -> self (8038.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...: 引数なし][ruby]{
IO.write("testfile", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//e......10 を指定][ruby]{
IO.write("testfile", "This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: A......omp = true][ruby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see... -
IO
# each(rs = $ / , chomp: false) -> Enumerator (8038.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...: 引数なし][ruby]{
IO.write("testfile", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//e......10 を指定][ruby]{
IO.write("testfile", "This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: A......omp = true][ruby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see...