98件ヒット
[1-98件を表示]
(0.175秒)
種類
- インスタンスメソッド (76)
- クラス (22)
クラス
- Float (22)
- Integer (21)
- Rational (22)
- TracePoint (11)
キーワード
- % (11)
-
/ (21) - TracePoint (11)
- div (11)
- modulo (11)
- quo (11)
-
raised
_ exception (11)
検索結果
先頭5件
-
ZeroDivisionError (58002.0)
-
整数に対して整数の 0 で除算を行ったときに発生します。
整数に対して整数の 0 で除算を行ったときに発生します。 -
TracePoint
# raised _ exception -> Exception (17108.0) -
発生した例外を返します。
...e RuntimeError :raise イベントのためのイベントフックの外側で実行し
た場合に発生します。
//emlist[例][ruby]{
trace = TracePoint.new(:raise) do |tp|
tp.raised_exception # => #<ZeroDivisionError: divided by 0>
end
trace.enable
begin
0/0
rescue
e... -
TracePoint (14008.0)
-
Kernel.#set_trace_func と同様の機能をオブジェクト指向的な API で 提供するクラスです。
...Kernel.#set_trace_func と同様の機能をオブジェクト指向的な API で
提供するクラスです。
//emlist[例:例外に関する情報を収集する][ruby]{
trace = TracePoint.new(:raise) do |tp|
p [tp.lineno, tp.event, tp.raised_exception]
end
# => #<TracePoint:0x007f786a452448......>
trace.enable
# => false
0 / 0
# => [5, :raise, #<ZeroDivisionError: divided by 0>]
//}
TracePoint.new または、TracePoint.trace で指定したブロック
は、メソッドの引数(上記の例では :raise)に対応するイベントが発生した時に
呼び出されます。
発生......いては、TracePoint.new を参照してくださ
い。
=== 参考
* Ruby VM アドベントカレンダー #12 TracePoint の紹介 (1): https://www.atdot.net/~ko1/diary/201212.html#d12
* Ruby VM アドベントカレンダー #13 TracePoint の紹介 (2): https://www.atdot.net/~ko1/diary/20... -
Integer
# div(other) -> Integer (11238.0) -
整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
...をもって整商とします。
other が Integer オブジェクトの場合、Integer#/ の結果と一致します。
div に対応する剰余メソッドは modulo です。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[例][ruby]{
7.div(2) # => 3
7.div......# => 3
begin
2.div(0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
end
begin
2.div(0.0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
# Integer#/ と違い、引数が Float でもゼロで割ることはできない
end
//}
@see Integer#fdiv, Integer#/, Integer#modulo... -
Integer
# / (other) -> Numeric (11220.0) -
除算の算術演算子。
...術演算子。
other が Integer の場合、整商(整数の商)を Integer で返します。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
other が Float、Rational、Complex の場合、普通の商を other と
同じクラス......her 二項演算の右側の引数(対象)
@return 計算結果
//emlist[例][ruby]{
7 / 2 # => 3
7 / -2 # => -4
7 / 2.0 # => 3.5
7 / Rational(2, 1) # => (7/2)
7 / Complex(2, 0) # => ((7/2)+0i)
begin
2 / 0
rescue => e
e # => #<ZeroDivisionError: divided by 0>
end
//}
@see Integer#div, Integer......#fdiv, Numeric#quo... -
Rational
# / (other) -> Rational | Float (8114.0) -
商を計算します。
...商を計算します。
@param other 自身を割る数
other に Float を指定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2)......# => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionError other が 0 の時に発生します。
@see Numeric#quo... -
Rational
# quo(other) -> Rational | Float (8114.0) -
商を計算します。
...商を計算します。
@param other 自身を割る数
other に Float を指定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2)......# => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionError other が 0 の時に発生します。
@see Numeric#quo... -
Float
# %(other) -> Float (8108.0) -
算術演算子。剰余を計算します。
...算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 剰余
3.0 % 1.2 # => 0.6000000000000001
3.0 % 0.0 # ZeroDivisionError
//}... -
Float
# modulo(other) -> Float (8108.0) -
算術演算子。剰余を計算します。
...算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 剰余
3.0 % 1.2 # => 0.6000000000000001
3.0 % 0.0 # ZeroDivisionError
//}...