クラス
-
ARGF
. class (18) - Array (56)
- BasicObject (1)
- Binding (1)
- Complex (2)
- Dir (3)
- Enumerator (1)
-
Enumerator
:: ArithmeticSequence (2) -
Enumerator
:: Chain (1) - File (1)
-
File
:: Stat (17) - Float (9)
- Hash (3)
- IO (25)
- Integer (71)
- MatchData (7)
- Method (3)
- Module (2)
- NilClass (1)
- Numeric (9)
- Object (7)
- Proc (3)
-
Process
:: Status (7) - Random (6)
- Range (8)
- Rational (8)
- Regexp (5)
-
RubyVM
:: AbstractSyntaxTree :: Node (4) -
RubyVM
:: InstructionSequence (2) - SignalException (1)
- String (24)
- Struct (3)
- Symbol (5)
- SystemCallError (1)
- SystemExit (1)
- Thread (3)
-
Thread
:: Backtrace :: Location (1) -
Thread
:: Mutex (1) -
Thread
:: Queue (3) -
Thread
:: SizedQueue (3) - Time (21)
- TracePoint (19)
- UnboundMethod (3)
モジュール
- Enumerable (5)
キーワード
- % (2)
- & (2)
- * (3)
- ** (1)
- + (1)
- - (1)
- -@ (1)
-
/ (1) - < (1)
- << (1)
- <= (1)
- <=> (3)
- == (1)
- === (1)
- =~ (3)
- > (1)
- >= (1)
- >> (2)
- [] (6)
- []= (3)
- ^ (1)
-
_ _ id _ _ (1) - abs (1)
- allbits? (1)
- anybits? (1)
- arity (3)
- at (1)
- begin (2)
- binding (1)
-
bit
_ length (1) - blksize (1)
- blocks (1)
-
bsearch
_ index (1) - bytes (1)
- bytesize (1)
-
callee
_ id (1) - ceil (4)
- chr (2)
- codepoints (6)
- combination (2)
-
const
_ source _ location (1) - count (7)
- cycle (2)
- day (1)
-
defined
_ class (1) -
delete
_ at (1) - denominator (5)
-
dev
_ major (1) -
dev
_ minor (1) - digits (2)
- disable (2)
- div (2)
- divmod (1)
- downto (2)
-
each
_ codepoint (6) - enable (2)
- enabled? (1)
- end (2)
- errno (1)
-
eval
_ script (1) - even? (1)
- event (1)
- exitstatus (1)
- fcntl (1)
- fdiv (1)
- fetch (3)
- fileno (3)
-
find
_ index (4) - first (4)
-
first
_ column (1) -
first
_ lineno (2) - flatten (1)
- flatten! (1)
- floor (4)
- gcd (1)
- gcdlcm (1)
- getbyte (3)
- gid (1)
-
gmt
_ offset (1) - gmtoff (1)
- hash (15)
- hex (1)
- hour (1)
- index (3)
- ino (1)
- insert (1)
- inspect (2)
-
instruction
_ sequence (1) - integer? (2)
- intern (2)
-
internal
_ encoding (2) - intersection (1)
- ioctl (1)
- last (4)
-
last
_ column (1) -
last
_ lineno (1) - lcm (1)
- left (1)
- length (8)
- lineno (4)
- magnitude (1)
- max (1)
- mday (1)
-
method
_ id (1) - min (1)
- mode (1)
- modulo (1)
- mon (1)
- month (1)
-
named
_ captures (1) - next (1)
- nlink (1)
- nobits? (1)
- nsec (1)
-
num
_ waiting (1) - numerator (4)
-
object
_ id (1) - oct (1)
- odd? (1)
- offset (2)
- ord (2)
- pack (2)
- parameters (1)
- path (1)
-
pending
_ interrupt? (1) - permutation (2)
- pid (2)
- pop (2)
- pos (3)
- pow (2)
- pred (1)
- print (2)
- printf (2)
- priority (1)
-
public
_ method (1) - pwrite (1)
-
raised
_ exception (1) - rand (3)
- rationalize (2)
- rdev (1)
-
rdev
_ major (1) -
rdev
_ minor (1) - readbyte (2)
- remainder (1)
-
repeated
_ combination (2) -
repeated
_ permutation (2) -
return
_ value (1) - rindex (3)
- rotate (1)
- rotate! (1)
- round (5)
-
safe
_ level (1) - sample (4)
- sec (1)
- seed (1)
- self (1)
-
set
_ encoding (6) - setbyte (1)
- shift (2)
- signo (1)
- size (15)
- size? (1)
- sleep (1)
-
source
_ location (4) - state (1)
- status (1)
- stopsig (1)
- subsec (1)
- succ (1)
- sum (1)
- sysseek (1)
- syswrite (1)
- taint (1)
- tainted? (1)
- tell (3)
- termsig (1)
- times (2)
-
to
_ a (1) -
to
_ f (1) -
to
_ i (10) -
to
_ int (3) -
to
_ r (1) -
to
_ s (1) -
to
_ sym (2) - truncate (4)
-
tv
_ nsec (1) -
tv
_ sec (1) -
tv
_ usec (1) - uid (1)
- unpack (1)
- untaint (1)
- upto (2)
- usec (1)
-
utc
_ offset (1) - wday (1)
-
world
_ readable? (1) -
world
_ writable? (1) - write (2)
-
write
_ nonblock (1) - yday (1)
- year (1)
- | (1)
- ~ (2)
検索結果
先頭5件
-
Integer
# integer? -> true (27310.0) -
常に真を返します。
常に真を返します。
//emlist[][ruby]{
1.integer? # => true
1.0.integer? # => false
//} -
Numeric
# to _ int -> Integer (18649.0) -
self.to_i と同じです。
self.to_i と同じです。
//emlist[例][ruby]{
(2+0i).to_int # => 2
Rational(3).to_int # => 3
//} -
Object
# to _ int -> Integer (18631.0) -
オブジェクトの Integer への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。
オブジェクトの Integer への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。
説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要に応じてサブクラスで定義すべきものです。
このメソッドを定義する条件は、
* 整数が使われるすべての場面で代置可能であるような、
* 整数そのものとみなせるようなもの
という厳しいものになっています。
//emlist[][ruby]{
class Foo
def to_int
1
end
end
ary = [:a, :b, :c]
p(... -
String
# codepoints -> [Integer] (18610.0) -
文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)
文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)
//emlist[例][ruby]{
#coding:UTF-8
"hello わーるど".codepoints
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
//}
ブロックが指定された場合は String#each_codepoint と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#e... -
String
# codepoints {|codepoint| block } -> self (18610.0) -
文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)
文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)
//emlist[例][ruby]{
#coding:UTF-8
"hello わーるど".codepoints
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
//}
ブロックが指定された場合は String#each_codepoint と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#e... -
String
# each _ codepoint {|codepoint| block } -> self (18610.0) -
文字列の各コードポイントに対して繰り返します。
文字列の各コードポイントに対して繰り返します。
UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE) 以外のエンコーディングに対しては
各文字のバイナリ表現由来の値になります。
//emlist[例][ruby]{
#coding:UTF-8
"hello わーるど".each_codepoint.to_a
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
"hello わーるど".encode('euc-jp').each_codepoint.to_a
# => [104, 101, 108, 1... -
Integer
# to _ int -> self (18313.0) -
self を返します。
self を返します。
//emlist[][ruby]{
10.to_i # => 10
//} -
ARGF
. class # codepoints -> Enumerator (18310.0) -
このメソッドは obsolete です。 代わりに ARGF.class#each_codepoint を使用してください。 使用すると警告メッセージが表示されます。
このメソッドは obsolete です。
代わりに ARGF.class#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。 -
ARGF
. class # codepoints { |c| . . . } -> self (18310.0) -
このメソッドは obsolete です。 代わりに ARGF.class#each_codepoint を使用してください。 使用すると警告メッセージが表示されます。
このメソッドは obsolete です。
代わりに ARGF.class#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。 -
ARGF
. class # each _ codepoint -> Enumerator (18310.0) -
self の各コードポイントに対して繰り返しブロックを呼びだします。
self の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
例:
# $ echo "line1\n" > test1.txt
# $ echo "line2\n" > test2.txt
# $ ruby test.rb test1.txt test2.txt
# test.rb
ARGF.each_codepoint # => #<Enumerator: ARGF:each_codepoint>
... -
ARGF
. class # each _ codepoint { |c| . . . } -> self (18310.0) -
self の各コードポイントに対して繰り返しブロックを呼びだします。
self の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
例:
# $ echo "line1\n" > test1.txt
# $ echo "line2\n" > test2.txt
# $ ruby test.rb test1.txt test2.txt
# test.rb
ARGF.each_codepoint # => #<Enumerator: ARGF:each_codepoint>
... -
ARGF
. class # internal _ encoding -> Encoding | nil (18310.0) -
ARGF から読み込んだ文字列の内部エンコーディングを返します。 内部エンコーディングが指定されていない場合は nil を返します。
ARGF から読み込んだ文字列の内部エンコーディングを返します。
内部エンコーディングが指定されていない場合は nil を返します。
まだ読み込み処理を始めていない場合は Encoding.default_external を返します。
ARGF.class#set_encoding で設定します。
例:
# $ ruby -Eutf-8 test.rb
# test.rb
ARGF.internal_encoding # => #<Encoding:UTF-8>
ARGF.set_encoding('utf-8','ascii')
ARG... -
ARGF
. class # print(*arg) -> nil (18310.0) -
引数を順に処理対象のファイルに出力します。
引数を順に処理対象のファイルに出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は Kernel.#print と同じです。
@param arg 出力するオブジェクトを任意個指定します。 -
ARGF
. class # printf(format , *arg) -> nil (18310.0) -
C 言語の printf と同じように、format に従い引数を 文字列に変換して処理対象のファイルに出力します。
C 言語の printf と同じように、format に従い引数を
文字列に変換して処理対象のファイルに出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は出力先を指定しない形式の Kernel.#printf と同じです。
@param format フォーマット文字列です。
@param arg フォーマットされる引数です。 -
Array
# intersection(*other _ arrays) -> Array (18310.0) -
自身と引数に渡された配列の共通要素を新しい配列として返します。 要素が重複する場合は、そのうちの1つのみを返します。 要素の順序は自身の順序を維持します。
自身と引数に渡された配列の共通要素を新しい配列として返します。
要素が重複する場合は、そのうちの1つのみを返します。
要素の順序は自身の順序を維持します。
@param other_arrays 自身と共通要素を取りたい配列を指定します。
配列以外のオブジェクトを指定した場合は to_ary
メソッドによる暗黙の型変換を試みます。
@raise TypeError 引数に配列以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
intersection... -
IO
# codepoints -> Enumerator (18310.0) -
このメソッドは obsolete です。 代わりに IO#each_codepoint を使用してください。
このメソッドは obsolete です。
代わりに IO#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。
IO の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
@see IO#each_codepoint -
IO
# codepoints {|c| . . . } -> self (18310.0) -
このメソッドは obsolete です。 代わりに IO#each_codepoint を使用してください。
このメソッドは obsolete です。
代わりに IO#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。
IO の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
@see IO#each_codepoint -
IO
# each _ codepoint -> Enumerator (18310.0) -
IO の各コードポイントに対して繰り返しブロックを呼びだします。
IO の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
//emlist[例][ruby]{
IO.write("testfile", "abcdeあ")
File.open("testfile") do |f|
f.each_codepoint { |i| p i }
end
# => 97
# 98
# 99
# 100
# 101
# 12354
//} -
IO
# each _ codepoint {|c| . . . } -> self (18310.0) -
IO の各コードポイントに対して繰り返しブロックを呼びだします。
IO の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
//emlist[例][ruby]{
IO.write("testfile", "abcdeあ")
File.open("testfile") do |f|
f.each_codepoint { |i| p i }
end
# => 97
# 98
# 99
# 100
# 101
# 12354
//} -
IO
# internal _ encoding -> Encoding | nil (18310.0) -
IO の内部エンコーディングを返します。 内部エンコーディングが指定されていない場合は nil を返します。
IO の内部エンコーディングを返します。
内部エンコーディングが指定されていない場合は nil を返します。
//emlist[例][ruby]{
IO.write("testfile", "abcde")
File.open("testfile") do |f|
p f.internal_encoding # => nil
f.set_encoding("ASCII-8BIT", "EUC-JP")
p f.internal_encoding # => #<Encoding:EUC-JP>
end
//} -
IO
# print(*arg) -> nil (18310.0) -
引数を IO ポートに順に出力します。引数を省略した場合は、$_ を出力します。
引数を IO ポートに順に出力します。引数を省略した場合は、$_ を出力します。
@param arg Kernel.#print と同じです。
@raise IOError 自身が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
$stdout.print("This is ", 100, " percent.\n") # => This is 100 percent.
//}
@see Kernel.#print -
IO
# printf(format , *arg) -> nil (18310.0) -
C 言語の printf と同じように、format に従い引数 を文字列に変換して、self に出力します。
C 言語の printf と同じように、format に従い引数
を文字列に変換して、self に出力します。
第一引数に IO を指定できないこと、引数を省略できないことを除けば Kernel.#printf と同じです。
@param format Kernel.#printf と同じです。print_format を参照してください。
@param arg Kernel.#printf と同じです。
@raise IOError 自身が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
@see Ker... -
Numeric
# integer? -> bool (18310.0) -
自身が Integer かそのサブクラスのインスタンスの場合にtrue を返し ます。そうでない場合に false を返します。
自身が Integer かそのサブクラスのインスタンスの場合にtrue を返し
ます。そうでない場合に false を返します。
Numeric のサブクラスは、このメソッドを適切に再定義しなければなりません。
//emlist[例][ruby]{
(1.0).integer? #=> false
(1).integer? #=> true
//}
@see Numeric#real? -
Object
# taint -> self (18310.0) -
何もせずに self を返します。 このメソッドは Ruby 2.7 から deprecated で、Ruby 3.2 で削除予定です。
何もせずに self を返します。
このメソッドは Ruby 2.7 から deprecated で、Ruby 3.2 で削除予定です。
@see Object#tainted?,Object#untaint,Object#freeze -
Object
# tainted? -> false (18310.0) -
常に false を返します。 全てのオブジェクトは常に untainted 扱いになりました。
常に false を返します。
全てのオブジェクトは常に untainted 扱いになりました。
このメソッドは Ruby 2.7から deprecated で、Ruby 3.2 で削除予定です。
@see Object#taint,Object#untaint -
Object
# untaint -> self (18310.0) -
何もせずに self を返します。
何もせずに self を返します。
このメソッドは Ruby 2.7 から deprecated で、Ruby 3.2 で削除予定です。
@see Object#taint,Object#tainted? -
String
# each _ codepoint -> Enumerator (18310.0) -
文字列の各コードポイントに対して繰り返します。
文字列の各コードポイントに対して繰り返します。
UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE) 以外のエンコーディングに対しては
各文字のバイナリ表現由来の値になります。
//emlist[例][ruby]{
#coding:UTF-8
"hello わーるど".each_codepoint.to_a
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
"hello わーるど".encode('euc-jp').each_codepoint.to_a
# => [104, 101, 108, 1... -
String
# intern -> Symbol (18310.0) -
文字列に対応するシンボル値 Symbol を返します。
文字列に対応するシンボル値 Symbol を返します。
なお、このメソッドの逆にシンボルに対応する文字列を得るには
Symbol#to_s または Symbol#id2name を使います。
シンボル文字列にはヌルキャラクタ("\0")、空の文字列の使用も可能です。
//emlist[例][ruby]{
p "foo".intern # => :foo
p "foo".intern.to_s == "foo" # => true
//} -
Symbol
# intern -> self (18310.0) -
self を返します。
self を返します。
例:
:foo.intern # => :foo
@see String#intern -
Thread
# pending _ interrupt?(error = nil) -> bool (18310.0) -
self の非同期例外のキューが空かどうかを返します。
self の非同期例外のキューが空かどうかを返します。
@param error 対象の例外クラスを指定します。
@see Thread.pending_interrupt? -
Integer
# bit _ length -> Integer (9364.0) -
self を表すのに必要なビット数を返します。
self を表すのに必要なビット数を返します。
「必要なビット数」とは符号ビットを除く最上位ビットの位置の事を意味しま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
//emlist[例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果][ruby]{
(-2**12-1).bit_length # => 13
(-2**12).bit_length # => 12
(-2**12+1).bit_length # => 12
-0x101.bit... -
Integer
# &(other) -> Integer (9310.0) -
ビット二項演算子。論理積を計算します。
ビット二項演算子。論理積を計算します。
@param other 数値
//emlist[][ruby]{
1 & 1 # => 1
2 & 3 # => 2
//} -
Integer
# -@ -> Integer (9310.0) -
単項演算子の - です。 self の符号を反転させたものを返します。
単項演算子の - です。
self の符号を反転させたものを返します。
//emlist[][ruby]{
- 10 # => -10
- -10 # => 10
//} -
Integer
# <<(bits) -> Integer (9310.0) -
シフト演算子。bits だけビットを左にシフトします。
シフト演算子。bits だけビットを左にシフトします。
@param bits シフトさせるビット数
//emlist[][ruby]{
printf("%#b\n", 0b0101 << 1) # => 0b1010
p -1 << 1 # => -2
//} -
Integer
# >>(bits) -> Integer (9310.0) -
シフト演算子。bits だけビットを右にシフトします。
シフト演算子。bits だけビットを右にシフトします。
右シフトは、符号ビット(最上位ビット(MSB))が保持されます。
bitsが実数の場合、小数点以下を切り捨てた値でシフトします。
@param bits シフトさせるビット数
//emlist[][ruby]{
printf("%#b\n", 0b0101 >> 1) # => 0b10
p -1 >> 1 # => -1
//} -
Integer
# [](nth) -> Integer (9310.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。
@param nth 何ビット目を指すかの数値
@param len 何ビット分を返すか
@param range 返すビットの範囲
@return self[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return sel... -
Integer
# [](nth , len) -> Integer (9310.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。
@param nth 何ビット目を指すかの数値
@param len 何ビット分を返すか
@param range 返すビットの範囲
@return self[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return sel... -
Integer
# [](range) -> Integer (9310.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。
@param nth 何ビット目を指すかの数値
@param len 何ビット分を返すか
@param range 返すビットの範囲
@return self[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return sel... -
Integer
# ^(other) -> Integer (9310.0) -
ビット二項演算子。排他的論理和を計算します。
ビット二項演算子。排他的論理和を計算します。
@param other 数値
//emlist[][ruby]{
1 ^ 1 # => 0
2 ^ 3 # => 1
//} -
Integer
# abs -> Integer (9310.0) -
self の絶対値を返します。
self の絶対値を返します。
//emlist[][ruby]{
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321
//} -
Integer
# ceil(ndigits = 0) -> Integer (9310.0) -
self と等しいかより大きな整数のうち最小のものを返します。
self と等しいかより大きな整数のうち最小のものを返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.ceil # => 1
1.ceil(2) # => 1
18.ceil(-1) # => 20
(-18).ceil(-1) # => -10
//}
@see Numeric#ceil -
Integer
# denominator -> Integer (9310.0) -
分母(常に1)を返します。
分母(常に1)を返します。
@return 分母を返します。
//emlist[][ruby]{
10.denominator # => 1
-10.denominator # => 1
//}
@see Integer#numerator -
Integer
# digits -> [Integer] (9310.0) -
base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。
base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。
//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}
self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。
//emlist[][ruby]{
-10.digits # Math::DomainError: out of domain が発生
//}
@return 位取り記数法で表した時の数... -
Integer
# digits(base) -> [Integer] (9310.0) -
base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。
base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。
//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}
self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。
//emlist[][ruby]{
-10.digits # Math::DomainError: out of domain が発生
//}
@return 位取り記数法で表した時の数... -
Integer
# div(other) -> Integer (9310.0) -
整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
整商(整数の商)を返します。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
other が Integer オブジェクトの場合、Integer#/ の結果と一致します。
div に対応する剰余メソッドは modulo です。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[例][ruby]{
7.div(2) # => 3
7.div(-2) # => -4
7.div(2.0) # => 3
7.div(Rational(2, 1)) # => 3
begin
2.div(0)
rescue => ... -
Integer
# divmod(other) -> [Integer , Numeric] (9310.0) -
self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。
self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし
て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。
@param other self を割る数。
@see Numeric#divmod -
Integer
# floor(ndigits = 0) -> Integer (9310.0) -
self と等しいかより小さな整数のうち最大のものを返します。
self と等しいかより小さな整数のうち最大のものを返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.floor # => 1
1.floor(2) # => 1
18.floor(-1) # => 10
(-18).floor(-1) # => -20
//}
@see Numeric#floor -
Integer
# gcd(n) -> Integer (9310.0) -
自身と整数 n の最大公約数を返します。
自身と整数 n の最大公約数を返します。
@raise ArgumentError n に整数以外のものを指定すると発生します。
//emlist[][ruby]{
2.gcd(2) # => 2
3.gcd(7) # => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
//}
また、self や n が 0 だった場合は、0 ではない方の整数の絶対値を返します。
//emlist[][ruby]{
3.gcd(... -
Integer
# gcdlcm(n) -> [Integer] (9310.0) -
自身と整数 n の最大公約数と最小公倍数の配列 [self.gcd(n), self.lcm(n)] を返します。
自身と整数 n の最大公約数と最小公倍数の配列 [self.gcd(n), self.lcm(n)]
を返します。
@raise ArgumentError n に整数以外のものを指定すると発生します。
//emlist[][ruby]{
2.gcdlcm(2) # => [2, 2]
3.gcdlcm(-7) # => [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1) # => [1, 4951760154835678088235319297]
//}
@see Integer#gc... -
Integer
# lcm(n) -> Integer (9310.0) -
自身と整数 n の最小公倍数を返します。
自身と整数 n の最小公倍数を返します。
@raise ArgumentError n に整数以外のものを指定すると発生します。
//emlist[][ruby]{
2.lcm(2) # => 2
3.lcm(-7) # => 21
((1<<31)-1).lcm((1<<61)-1) # => 4951760154835678088235319297
//}
また、self や n が 0 だった場合は、0 を返します。
//emlist[][ruby]{
3.lcm(0) ... -
Integer
# magnitude -> Integer (9310.0) -
self の絶対値を返します。
self の絶対値を返します。
//emlist[][ruby]{
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321
//} -
Integer
# next -> Integer (9310.0) -
self の次の整数を返します。
self の次の整数を返します。
//emlist[][ruby]{
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
//}
@see Integer#pred -
Integer
# numerator -> Integer (9310.0) -
分子(常に自身)を返します。
分子(常に自身)を返します。
@return 分子を返します。
//emlist[][ruby]{
10.numerator # => 10
-10.numerator # => -10
//}
@see Integer#denominator -
Integer
# ord -> Integer (9310.0) -
自身を返します。
自身を返します。
//emlist[][ruby]{
10.ord #=> 10
# String#ord
?a.ord #=> 97
//}
@see String#ord -
Integer
# pow(other , modulo) -> Integer (9310.0) -
算術演算子。冪(べき乗)を計算します。
算術演算子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。
//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0 # => 1
0 ** 0 # => 1
... -
Integer
# pred -> Integer (9310.0) -
self から -1 した値を返します。
self から -1 した値を返します。
//emlist[][ruby]{
1.pred #=> 0
(-1).pred #=> -2
//}
@see Integer#next -
Integer
# round(ndigits = 0 , half: :up) -> Integer (9310.0) -
self ともっとも近い整数を返します。
self ともっとも近い整数を返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の値の丸め方を指定します。
サポートされている値は以下の通りです。
* :up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に丸められます。
* :down: 0に近い方に丸められます。
//emlist[][ruby]{
1.round # =... -
Integer
# size -> Integer (9310.0) -
整数の実装上のサイズをバイト数で返します。
整数の実装上のサイズをバイト数で返します。
//emlist[][ruby]{
p 1.size # => 8
p 0x1_0000_0000.size # => 8
//}
@see Integer#bit_length -
Integer
# succ -> Integer (9310.0) -
self の次の整数を返します。
self の次の整数を返します。
//emlist[][ruby]{
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
//}
@see Integer#pred -
Integer
# truncate(ndigits = 0) -> Integer (9310.0) -
0 から self までの整数で、自身にもっとも近い整数を返します。
0 から self までの整数で、自身にもっとも近い整数を返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.truncate # => 1
1.truncate(2) # => 1
18.truncate(-1) # => 10
(-18).truncate(-1) # => -10
//}
@see Numeric#truncate -
Integer
# upto(max) {|n| . . . } -> Integer (9310.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。
@param max 数値
@return self を返します。
//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}
@see Integer#downto, Numeric#step, Integer#times -
Integer
# |(other) -> Integer (9310.0) -
ビット二項演算子。論理和を計算します。
ビット二項演算子。論理和を計算します。
@param other 数値
//emlist[][ruby]{
1 | 1 # => 1
2 | 3 # => 3
//} -
Integer
# ~ -> Integer (9310.0) -
ビット演算子。否定を計算します。
ビット演算子。否定を計算します。
//emlist[][ruby]{
~1 # => -2
~3 # => -4
~-4 # => 3
//} -
TracePoint
# lineno -> Integer (9310.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
//} -
Integer
# to _ i -> self (9013.0) -
self を返します。
self を返します。
//emlist[][ruby]{
10.to_i # => 10
//} -
Integer
# %(other) -> Numeric (9010.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}
@param other 二項演算の右側の引数(対象)
@return 計算結果 -
Integer
# *(other) -> Numeric (9010.0) -
算術演算子。積を計算します。
算術演算子。積を計算します。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[][ruby]{
2 * 3 # => 6
//} -
Integer
# **(other) -> Numeric (9010.0) -
算術演算子。冪(べき乗)を計算します。
算術演算子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。
//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0 # => 1
0 ** 0 # => 1
... -
Integer
# +(other) -> Numeric (9010.0) -
算術演算子。和を計算します。
算術演算子。和を計算します。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[][ruby]{
3 + 4 # => 7
//} -
Integer
# -(other) -> Numeric (9010.0) -
算術演算子。差を計算します。
算術演算子。差を計算します。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[][ruby]{
4 - 1 #=> 3
//} -
Integer
# / (other) -> Numeric (9010.0) -
除算の算術演算子。
除算の算術演算子。
other が Integer の場合、整商(整数の商)を Integer で返します。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
other が Float、Rational、Complex の場合、普通の商を other と
同じクラスのインスタンスで返します。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[例][ruby]{
7 / 2 # => 3
7 / -2 # => -4
7 / 2.0 # => 3.5
7 / Rational(2, 1) # => (7/2)
7... -
Integer
# <(other) -> bool (9010.0) -
比較演算子。数値として小さいか判定します。
比較演算子。数値として小さいか判定します。
@param other 比較対象の数値
@return self よりも other が大きい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 < 1 # => false
1 < 2 # => true
//} -
Integer
# <=(other) -> bool (9010.0) -
比較演算子。数値として等しいまたは小さいか判定します。
比較演算子。数値として等しいまたは小さいか判定します。
@param other 比較対象の数値
@return self よりも other の方が大きい場合か、
両者が等しい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 <= 0 # => false
1 <= 1 # => true
1 <= 2 # => true
//} -
Integer
# <=>(other) -> -1 | 0 | 1 | nil (9010.0) -
self と other を比較して、self が大きい時に1、等しい時に 0、小さい時 に-1、比較できない時に nil を返します。
self と other を比較して、self が大きい時に1、等しい時に 0、小さい時
に-1、比較できない時に nil を返します。
@param other 比較対象の数値
@return -1 か 0 か 1 か nil のいずれか
//emlist[][ruby]{
1 <=> 2 # => -1
1 <=> 1 # => 0
2 <=> 1 # => 1
2 <=> '' # => nil
//} -
Integer
# ==(other) -> bool (9010.0) -
比較演算子。数値として等しいか判定します。
比較演算子。数値として等しいか判定します。
@param other 比較対象の数値
@return self と other が等しい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 == 2 # => false
1 == 1.0 # => true
//} -
Integer
# ===(other) -> bool (9010.0) -
比較演算子。数値として等しいか判定します。
比較演算子。数値として等しいか判定します。
@param other 比較対象の数値
@return self と other が等しい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 == 2 # => false
1 == 1.0 # => true
//} -
Integer
# >(other) -> bool (9010.0) -
比較演算子。数値として大きいか判定します。
比較演算子。数値として大きいか判定します。
@param other 比較対象の数値
@return self よりも other の方が小さい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 > 0 # => true
1 > 1 # => false
//} -
Integer
# >=(other) -> bool (9010.0) -
比較演算子。数値として等しいまたは大きいか判定します。
比較演算子。数値として等しいまたは大きいか判定します。
@param other 比較対象の数値
@return self よりも other の方が小さい場合か、
両者が等しい場合 true を返します。
そうでなければ false を返します。
//emlist[][ruby]{
1 >= 0 # => true
1 >= 1 # => true
1 >= 2 # => false
//} -
Integer
# allbits?(mask) -> bool (9010.0) -
self & mask の全てのビットが 1 なら true を返します。
self & mask の全てのビットが 1 なら true を返します。
self & mask == mask と等価です。
@param mask ビットマスクを整数で指定します。
//emlist[][ruby]{
42.allbits?(42) # => true
0b1010_1010.allbits?(0b1000_0010) # => true
0b1010_1010.allbits?(0b1000_0001) # => false
0b1000_0010.allbits?(0b1010_1010) # => false
//}
@s... -
Integer
# anybits?(mask) -> bool (9010.0) -
self & mask のいずれかのビットが 1 なら true を返します。
self & mask のいずれかのビットが 1 なら true を返します。
self & mask != 0 と等価です。
@param mask ビットマスクを整数で指定します。
//emlist[][ruby]{
42.anybits?(42) # => true
0b1010_1010.anybits?(0b1000_0010) # => true
0b1010_1010.anybits?(0b1000_0001) # => true
0b1000_0010.anybits?(0b0010_1100) # => false
//}
@see... -
Integer
# chr -> String (9010.0) -
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)
p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}
引数無しで呼ばれた場合は self ... -
Integer
# chr(encoding) -> String (9010.0) -
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)
p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}
引数無しで呼ばれた場合は self ... -
Integer
# downto(min) -> Enumerator (9010.0) -
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。
@param min 数値
@return self を返します。
//emlist[][ruby]{
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
//}
@see Integer#upto, Numeric#step, Integer#times -
Integer
# downto(min) {|n| . . . } -> self (9010.0) -
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。
@param min 数値
@return self を返します。
//emlist[][ruby]{
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
//}
@see Integer#upto, Numeric#step, Integer#times -
Integer
# even? -> bool (9010.0) -
自身が偶数であれば真を返します。 そうでない場合は偽を返します。
自身が偶数であれば真を返します。
そうでない場合は偽を返します。
//emlist[][ruby]{
10.even? # => true
5.even? # => false
//} -
Integer
# fdiv(other) -> Numeric (9010.0) -
self を other で割った商を Float で返します。 ただし Complex が関わる場合は例外です。 その場合も成分は Float になります。
self を other で割った商を Float で返します。
ただし Complex が関わる場合は例外です。
その場合も成分は Float になります。
@param other self を割る数を指定します。
例:
654321.fdiv(13731) # => 47.652829364212366
654321.fdiv(13731.24) # => 47.65199646936475
-1234567890987654321.fdiv(13731) # => -89910996357705.52
-1234567890987654... -
Integer
# inspect(base=10) -> String (9010.0) -
整数を 10 進文字列表現に変換します。
整数を 10 進文字列表現に変換します。
引数を指定すれば、それを基数とした文字列表
現に変換します。
//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}
@return 数値の文字列表現
@param base 基数となる 2 - 36 の数値。
@raise ArgumentError base に 2 - 36 以外の数値を指定した場合に発生します。 -
Integer
# modulo(other) -> Numeric (9010.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}
@param other 二項演算の右側の引数(対象)
@return 計算結果 -
Integer
# nobits?(mask) -> bool (9010.0) -
self & mask のすべてのビットが 0 なら true を返します。
self & mask のすべてのビットが 0 なら true を返します。
self & mask == 0 と等価です。
@param mask ビットマスクを整数で指定します。
//emlist[][ruby]{
42.nobits?(42) # => false
0b1010_1010.nobits?(0b1000_0010) # => false
0b1010_1010.nobits?(0b1000_0001) # => false
0b0100_0101.nobits?(0b1010_1010) # => true
//}
@see In... -
Integer
# odd? -> bool (9010.0) -
自身が奇数であれば真を返します。 そうでない場合は偽を返します。
自身が奇数であれば真を返します。
そうでない場合は偽を返します。
//emlist[][ruby]{
5.odd? # => true
10.odd? # => false
//} -
Integer
# pow(other) -> Numeric (9010.0) -
算術演算子。冪(べき乗)を計算します。
算術演算子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。
//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0 # => 1
0 ** 0 # => 1
... -
Integer
# rationalize -> Rational (9010.0) -
自身を Rational に変換します。
自身を Rational に変換します。
@param eps 許容する誤差
引数 eps は常に無視されます。
//emlist[][ruby]{
2.rationalize # => (2/1)
2.rationalize(100) # => (2/1)
2.rationalize(0.1) # => (2/1)
//} -
Integer
# rationalize(eps) -> Rational (9010.0) -
自身を Rational に変換します。
自身を Rational に変換します。
@param eps 許容する誤差
引数 eps は常に無視されます。
//emlist[][ruby]{
2.rationalize # => (2/1)
2.rationalize(100) # => (2/1)
2.rationalize(0.1) # => (2/1)
//} -
Integer
# remainder(other) -> Numeric (9010.0) -
self を other で割った余り r を返します。
self を other で割った余り r を返します。
r の符号は self と同じになります。
@param other self を割る数。
//emlist[][ruby]{
5.remainder(3) # => 2
-5.remainder(3) # => -2
5.remainder(-3) # => 2
-5.remainder(-3) # => -2
-1234567890987654321.remainder(13731) # => -6966
-1234567890987654321.remainder(13731.24) #... -
Integer
# times -> Enumerator (9010.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
self 回だけ繰り返します。
self が正の整数でない場合は何もしません。
またブロックパラメータには 0 から self - 1 までの数値が渡されます。
//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
//}
@see Integer#upto, Integer#downto,... -
Integer
# times {|n| . . . } -> self (9010.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
self 回だけ繰り返します。
self が正の整数でない場合は何もしません。
またブロックパラメータには 0 から self - 1 までの数値が渡されます。
//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
//}
@see Integer#upto, Integer#downto,... -
Integer
# to _ f -> Float (9010.0) -
self を浮動小数点数(Float)に変換します。
self を浮動小数点数(Float)に変換します。
self が Float の範囲に収まらない場合、Float::INFINITY を返します。
//emlist[][ruby]{
1.to_f # => 1.0
(Float::MAX.to_i * 2).to_f # => Infinity
(-Float::MAX.to_i * 2).to_f # => -Infinity
//} -
Integer
# to _ r -> Rational (9010.0) -
自身を Rational に変換します。
自身を Rational に変換します。
//emlist[][ruby]{
1.to_r # => (1/1)
(1<<64).to_r # => (18446744073709551616/1)
//} -
Integer
# to _ s(base=10) -> String (9010.0) -
整数を 10 進文字列表現に変換します。
整数を 10 進文字列表現に変換します。
引数を指定すれば、それを基数とした文字列表
現に変換します。
//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}
@return 数値の文字列表現
@param base 基数となる 2 - 36 の数値。
@raise ArgumentError base に 2 - 36 以外の数値を指定した場合に発生します。 -
Integer
# upto(max) -> Enumerator (9010.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。
@param max 数値
@return self を返します。
//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}
@see Integer#downto, Numeric#step, Integer#times