種類
- インスタンスメソッド (306)
- 文書 (67)
- 特異メソッド (24)
ライブラリ
- ビルトイン (246)
- shell (12)
-
shell
/ command-processor (12) -
shell
/ filter (12) - socket (12)
- zlib (36)
クラス
- BasicSocket (12)
-
Encoding
:: Converter (48) -
Enumerator
:: ArithmeticSequence (7) - File (24)
- IO (12)
- Integer (23)
- MatchData (48)
- Random (36)
- Regexp (12)
- Shell (12)
-
Shell
:: CommandProcessor (12) -
Shell
:: Filter (12) - SignalException (12)
- SystemCallError (12)
- SystemExit (12)
-
Zlib
:: GzipReader (36)
キーワード
-
/ (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - =~ (12)
-
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 5 . 0 (8) - Ruby用語集 (12)
- [] (18)
- delete (12)
- div (12)
- end (12)
- errno (12)
- getc (12)
- getpeereid (12)
- hash (7)
- lineno (12)
- offset (24)
-
primitive
_ convert (48) - rand (36)
- readbyte (12)
- readchar (12)
-
ruby 1
. 6 feature (12) - signo (12)
- status (12)
- test (18)
- unlink (12)
- 制御構造 (12)
検索結果
先頭5件
-
Integer
# div(other) -> Integer (21149.0) -
整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
...ます。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
other が Integer オブジェクトの場合、Integer#/ の結果と一致します。
div に対応する剰余メソッドは modulo です。
@param other 二項演算の右側......# => 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 (21030.0) -
除算の算術演算子。
...除算の算術演算子。
other が Integer の場合、整商(整数の商)を Integer で返します。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
other が Float、Rational、Complex の場合、普通の商を other と
同......側の引数(対象)
@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... -
MatchData
# begin(n) -> Integer | nil (18238.0) -
n 番目の部分文字列先頭のオフセットを返します。
...範囲外の n を指定した場合に発生します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.begin(0) # => 0
p $~.begin(1) # => 0
p $~.begin(2) # => 3
p $~.begin(3) # => nil
p $~.begin(4) # => `begin': index 4 out of matches (IndexError)
//}
@see MatchData#end... -
制御構造 (260.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...ase
繰り返し:
* while
* until
* for
* break
* next
* redo
* retry
例外処理:
* raise
* begin
その他:
* return
* BEGIN
* END
Rubyでは(Cなどとは異なり)制御構造は式であって、何らかの値を返すものが
あります(返......キーワードを通じてより強力なパターンマッチ構文を提供しています。
//emlist[][ruby]{
case {a: 1, b: 2, c: 3}
in a: Integer => m
"matched: #{m}"
else
"not matched"
end
# => "matched: 1"
//}
パターンマッチ構文についてはspec/pattern_matchingで説明......した値が真の間、左辺を繰り返し実行します。
左辺の式が begin 節である場合にはそれを最初に一回評価してから繰り返します。
//emlist[例][ruby]{
send_request(data)
begin
res = get_response()
end while res == 'Continue'
//}
while 修飾した式... -
MatchData
# offset(n) -> [Integer , Integer] | [nil , nil] (218.0) -
n 番目の部分文字列のオフセットの配列 [start, end] を返 します。
...]{
[ self.begin(n), self.end(n) ]
//}
と同じです。n番目の部分文字列がマッチしていなければ
[nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を指定した場合に発生します。
@see MatchData#begin, MatchDa... -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (218.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
...う名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返し......('year') # => [0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end......0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end, MatchData#offset... -
BasicSocket
# getpeereid -> [Integer , Integer] (208.0) -
Unix ドメインソケットにおいて接続相手の euid と egid を 返します。
...が Unix ドメインソケットでない場合の返り値は
不定です。
require 'socket'
Socket.unix_server_loop("/tmp/sock") {|s|
begin
euid, egid = s.getpeereid
# Check the connected client is myself or not.
next if euid != Process.uid
# do s... -
Ruby用語集 (144.0)
-
Ruby用語集 A B C D E F G I J M N O R S Y
...大きな整数オブジェクトが属す
クラスだった。Ruby 2.4 で Fixnum と共に Integer に一本化された。
このとき Bignum は形式的には残されたが単なる Integer のエイリアスとなった。
: blade
Ruby の各種メーリングリストのアーカイ......く実装するための手法の一つ。
例えば新しい数値クラス N を定義し、Integer と N の演算を可能にしたいとする。
Integer と N の加算を行うと、Integer 側では相手が未知のため、自身を引数に
まず相手側の N#coerce を呼ぶ。N......ジェクトの順序関係を表す
演算子 <=> の俗称。
: 埋め込みドキュメント
: embedded document
ソースコード中の =begin 行から =end 行まで。コメントとみなされ実行されない。
その名の通り、この部分にコードのドキュメント... -
Random
# rand(max) -> Integer | Float (138.0) -
一様な擬似乱数を発生させます。
...範囲から除かれます。
range.end - range.begin が整数を返す場合は range.begin + self.rand((range.end - range.begin) + e)
の値を返します(e は終端を含む場合は1、含まない場合は0です)。
range.end - range.begin が実数を返す場合も同様です。
この......ge 発生させる乱数値の範囲を Range オブジェクトで指定します。
range.end - range.begin は数値である必要があり、
range.begin + 数値 が適切な値を返す必要があります。
@raise Errno::EDOM rand(1..Float::INFINITY) などのよ...