別のキーワード
種類
- インスタンスメソッド (55)
- 特異メソッド (12)
検索結果
先頭5件
-
Integer
# |(other) -> Integer (18213.0) -
ビット二項演算子。論理和を計算します。
...ビット二項演算子。論理和を計算します。
@param other 数値
例:
1 | 1 # => 1
2 | 3 # => 3... -
Integer
# <=>(other) -> -1 | 0 | 1 | nil (6404.0) -
self と other を比較して、self が大きい時に1、等しい時に 0、小さい時 に-1、比較できない時に nil を返します。
...、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
# upto(max) {|n| . . . } -> Fixnum | Bignum (225.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
...ずつ増やしながら繰り返します。
self > max であれば何もしません。
@param max 数値
@return self を返します。
例:
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
@see Integer#downto, Numeric#step, Integer#times... -
Integer
# upto(max) {|n| . . . } -> Integer (224.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
...ずつ増やしながら繰り返します。
self > max であれば何もしません。
@param max 数値
@return self を返します。
例:
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
@see Integer#downto, Numeric#step, Integer#times... -
Integer
# downto(min) {|n| . . . } -> self (208.0) -
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。
...から min まで 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。
@param min 数値
@return self を返します。
例:
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
@see Integer#upto, Numeric#step, Integer#times... -
Integer
# times {|n| . . . } -> self (208.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
...数値が渡されます。
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
@see Integer#upto, Integer#downto, Numeric#step... -
Integer
# next -> Fixnum | Bignum (203.0) -
self の次の整数を返します。
...self の次の整数を返します。
例:
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
@see Integer#pred... -
Integer
# succ -> Fixnum | Bignum (203.0) -
self の次の整数を返します。
...self の次の整数を返します。
例:
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
@see Integer#pred... -
Integer
# ceil(ndigits = 0) -> Integer | Float (202.0) -
self と等しいかより大きな整数のうち最小のものを返します。
...負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.ceil # => 1
1.ceil(2) # => 1.0
18.ceil(-1) # => 20
(-18).ceil(-1) # => -10
//}
@see Numeric#ceil... -
Integer
# floor(ndigits = 0) -> Integer | Float (202.0) -
self と等しいかより小さな整数のうち最大のものを返します。
...負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.floor # => 1
1.floor(2) # => 1.0
18.floor(-1) # => 10
(-18).floor(-1) # => -20
//}
@see Numeric#floor... -
Integer
# round(ndigits = 0 , half: :up) -> Integer | Float (202.0) -
self ともっとも近い整数を返します。
...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の値の......=> 1
1.round(2) # => 1.0
15.round(-1) # => 20
(-15).round(-1) #=> -20
25.round(-1, half: :up) # => 30
25.round(-1, half: :down) # => 20
25.round(-1, half: :even) # => 20
35.round(-1, half: :up) # => 40
35.round(-1, half: :down) # => 30
35.round(-1, half: :even) # => 4......0
(-25).round(-1, half: :up) # => -30
(-25).round(-1, half: :down) # => -20
(-25).round(-1, half: :even) # => -20
//}
@see Numeric#round... -
Integer
# truncate(ndigits = 0) -> Integer | Float (202.0) -
0 から self までの整数で、自身にもっとも近い整数を返します。
...数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.truncate # => 1
1.truncate(2) # => 1.0
18.truncate(-1) #=> 10
(-18).truncate(-1) #=> -10
//}
@see Numeric#trunca... -
Integer
. each _ prime(upper _ bound) {|prime| . . . } -> object (202.0) -
全ての素数を列挙し、それぞれの素数をブロックに渡して評価します。
全ての素数を列挙し、それぞれの素数をブロックに渡して評価します。
@param upper_bound 任意の正の整数を指定します。列挙の上界です。
nil が与えられた場合は無限に列挙し続けます。
@return ブロックの最後に評価された値を返します。
ブロックが与えられなかった場合は、Enumerator と互換性のある外部イテレータを返します。
@see Prime#each -
Integer
# [](nth) -> Integer (125.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
...ないのは、Numeric 関連クラスが
immutable であるためです。
例:
a = 0b11001100101010
30.downto(0) do |n| print a[n] end
# => 0000000000000000011001100101010
a = 9**15
50.downto(0) do |n|
print a[n]
end
# => 000101110110100000111000011110010100111100010111001... -
Integer
# upto(max) -> Enumerator (125.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
...ずつ増やしながら繰り返します。
self > max であれば何もしません。
@param max 数値
@return self を返します。
例:
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
@see Integer#downto, Numeric#step, Integer#times... -
Integer
# downto(min) -> Enumerator (108.0) -
self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。
...から min まで 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。
@param min 数値
@return self を返します。
例:
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
@see Integer#upto, Numeric#step, Integer#times... -
Integer
# times -> Enumerator (108.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
...数値が渡されます。
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
@see Integer#upto, Integer#downto, Numeric#step... -
Integer
. each _ prime(upper _ bound) -> Enumerator (102.0) -
全ての素数を列挙し、それぞれの素数をブロックに渡して評価します。
全ての素数を列挙し、それぞれの素数をブロックに渡して評価します。
@param upper_bound 任意の正の整数を指定します。列挙の上界です。
nil が与えられた場合は無限に列挙し続けます。
@return ブロックの最後に評価された値を返します。
ブロックが与えられなかった場合は、Enumerator と互換性のある外部イテレータを返します。
@see Prime#each