検索結果
先頭5件
-
Kernel
$ $ DEBUG -> bool (21207.0) -
この値が真のときはインタプリタがデバッグモードになります。
...この値が真のときはインタプリタがデバッグモードになります。
コマンドラインオプション -d でセットされます。
スクリプトから代入することもできます。
デバッグモードでは、通常モードに比べて以下の違いがあり......になります。
Thread.abort_on_exception を
true にセットするのと同じ効果です。
* Thread.abort_on_exception= の効果がなくなります。
* 例外を捕捉しているかどうかに関係なく、
例外が発生した時点で $stderr にそれが出力されま......す。
スクリプトの処理は続行されます。
この変数はグローバルスコープです。
@see spec/rubycmd... -
Kernel
$ $ -d -> bool (9107.0) -
この値が真のときはインタプリタがデバッグモードになります。
...この値が真のときはインタプリタがデバッグモードになります。
コマンドラインオプション -d でセットされます。
スクリプトから代入することもできます。
デバッグモードでは、通常モードに比べて以下の違いがあり......になります。
Thread.abort_on_exception を
true にセットするのと同じ効果です。
* Thread.abort_on_exception= の効果がなくなります。
* 例外を捕捉しているかどうかに関係なく、
例外が発生した時点で $stderr にそれが出力されま......す。
スクリプトの処理は続行されます。
この変数はグローバルスコープです。
@see spec/rubycmd... -
irb (6246.0)
-
irb は Interactive Ruby の略です。 irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
...irb は Interactive Ruby の略です。
irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
=== irb の使い方
Ruby さえ知っていれば irb を使うのは簡単です。
irb コマンドを実行すると、以下のようなプロン......す。
readline ライブラリがインストールされている時には
自動的にコマンドライン編集や履歴の機能が使えるようになります。
=== irb のコマンドラインオプション
irb [options] file_name opts
options:
-f ~/.irbrc を読......い
-m bc モード (分数と行列の計算ができる)
-d $DEBUG を true にする (ruby -d と同じ)
-w ruby -w と同じ
-W[level=2] ruby -W と同じ
-r library ruby -r と同じ
-I ruby -I と同じ
-U......
-d $DEBUG を true にする (ruby -d と同じ)
-w ruby -w と同じ
-W[level=2] ruby -W と同じ
-r library ruby -r と同じ
-I ruby -I と同じ
-U ruby -U と同じ
-E enc ruby -E と同じ
--v... -
Kernel
. # caller(range) -> [String] | nil (6212.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...start 段上の呼び出し元の情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した......す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in......p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
de... -
Kernel
. # caller(start = 1) -> [String] | nil (6212.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...start 段上の呼び出し元の情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した......す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in......p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
de... -
Kernel
. # caller(start , length) -> [String] | nil (6212.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...start 段上の呼び出し元の情報を $@
の形式のバックトレース(文字列の配列)として返します。
トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した......す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in......p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
de... -
制御構造 (3024.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...:
* if
* unless
* case
繰り返し:
* while
* until
* for
* break
* next
* redo
* retry
例外処理:
* raise
* begin
その他:
* return
* BEGIN
* END
Rubyでは(Cなどとは異なり)制御構造は式であって、何らかの値を......条件式が正規表現のリテラルである時には特別に
//emlist[][ruby]{
$_ =~ リテラル
//}
であるかのように評価されます。
==== if 修飾子
//emlist[例][ruby]{
print "debug\n" if $DEBUG
//}
文法:
式 if 式
右辺の条件が成立する時に、......呼び出しにおける break, next, redo
をまとめると以下のようになります。
//emlist[][ruby]{
def iter
# (a)
# :
# (b)
yield
# (c)
# :
# (d)
end
iter { redo } # -> (b) へ飛ぶ
iter { next } # -> (c) へ飛ぶ
iter { break } # -> (d) へ飛ぶ
//}
(a) は...