るりまサーチ

最速Rubyリファレンスマニュアル検索!
624件ヒット [1-100件を表示] (0.042秒)

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. module >
  4. float >
  5. complex >

ライブラリ

クラス

キーワード

検索結果

<< 1 2 3 ... > >>

Numeric#to_int -> Integer (18220.0)

self.to_i と同じです。

...self.to_i と同じです。

//emlist[例][ruby]{
(2+0i).to_int # => 2
Rational(3).to_int # => 3
//}...

Object#to_int -> Integer (18214.0)

オブジェクトの Integer への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...が使われるすべての場面で代置可能であるような、
* 整数そのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_int
1
end
end

ary = [:a, :b, :c]
p(ary[Foo.new]) # => :b
//}

@see Kernel.#Integer...

Integer#to_int -> self (15208.0)

self を返します。

...self を返します。

//emlist[][ruby]{
10.to_i # => 10
//}...

String#%(args) -> String (323.0)

printf と同じ規則に従って args をフォーマットします。

...st[例][ruby]{
p "i = %d" % 10 # => "i = 10"
p "i = %x" % 10 # => "i = a"
p "i = %o" % 10 # => "i = 12"

p "i = %#d" % 10 # => "i = 10"
p "i = %#x" % 10 # => "i = 0xa"
p "i = %#o" % 10 # => "i = 012"

p "%d" % 10 # => "10"
p "%d,%o" % [10, 10] # => "10,12"...
...//}

=== sprintf フォーマット

Ruby
の sprintf フォーマットは基本的に C 言語の sprintf(3)
のものと同じです。ただし、short や long などの C 特有の型に対する修飾子が
ないこと、2進数の指示子(%b, %B)が存在すること、sprintf のすべ...
...ての方言をサ
ポートしていないこと(%': 3桁区切り)などの違いがあります。

Ruby
には整数の大きさに上限がないので、%b, %B, %o, %x, %X
に負の数を与えると (左側に無限に1が続くとみなせるので)
..f のような表示をします。絶...

Object#public_method(name) -> Method (125.0)

オブジェクトの public メソッド name をオブジェクト化した Method オブジェクトを返します。

...protected メソッド名、 private メソッド名を引数として与えると発生します。

//emlist[][ruby]{
1.public_method(:to_int) #=> #<Method: Integer#to_int>
1.public_method(:p) # method `p' for class `Integer' is private (NameError)
//}

@see Object#method,Object#publ...

絞り込み条件を変える

Array#[](start, length) -> Array | nil (122.0)

start 番目から length 個の要素を含む部分配列を返します。 start が自身の範囲外となる時は nil を返します。ただし、start が配列の長さに等しいときは空の配列を返します。 length が負の時は nil を返します。

...倣します。
末尾の要素が -1 番目になります。
整数以外のオブジェクトを指定した場合は to_int メソッドによ
る暗黙の型変換を試みます。

@param length 生成したい部分配列の長さを整数で指定し...
...指定した場合は to_int メソッドに
よる暗黙の型変換を試みます。

@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。

//emlist[例][ruby]{
a = [ "a", "b", "c",...
..."d", "e" ]
a[0, 1] #=> ["a"]
a[-1, 1] #=> ["e"]
a[0, 10] #=> ["a", "b", "c", "d", "e"]
a[0, 0] #=> []
a[0, -1] #=> nil
a[10, 1] #=> nil

# 特殊なケース。start が自身の長さと同じ場合には以下のようになります。
a[5] #=> nil
a[5, 1] #=> []
//}...

Range#first(n) -> [object] (120.0)

最初の n 要素を返します。範囲内に要素が含まれない場合は空の配列を返します。

...を返します。

@param n 取得する要素数を整数で指定します。整数以外のオブジェクトを指定
した場合は to_int メソッドによる暗黙の型変換を試みます。

@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジ...
...ェクトを
指定した場合に発生します。

@raise ArgumentError n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
(10..20).first(3) # => [10, 11, 12]
//}

@see Range#last, 12697...

Array#combination(n) -> Enumerator (119.0)

サイズ n の組み合わせをすべて生成し、それを引数としてブロックを実行します。

... to_int メソッドによる暗
黙の型変換を試みます。

@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4]
a.combination(1).to_a #=> [[...
...2],[3],[4]]
a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
a.combination(4).to_a #=> [[1,2,3,4]]
a.combination(0).to_a #=> [[]]: one combination of length 0
a.combination(5).to_a #=> [] : no combinations of length 5
/...
...た配列の各要素を引数としてブロックを実
行して self を返します。

//emlist[例][ruby]{
a = [1, 2, 3, 4]
result = []
a.combination(2) {|e| result << e} # => [1,2,3,4]
result #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
//}

@see Array#permutation, Array#repeated_combination...

Array#combination(n) {|c| block } -> self (119.0)

サイズ n の組み合わせをすべて生成し、それを引数としてブロックを実行します。

... to_int メソッドによる暗
黙の型変換を試みます。

@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4]
a.combination(1).to_a #=> [[...
...2],[3],[4]]
a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
a.combination(4).to_a #=> [[1,2,3,4]]
a.combination(0).to_a #=> [[]]: one combination of length 0
a.combination(5).to_a #=> [] : no combinations of length 5
/...
...た配列の各要素を引数としてブロックを実
行して self を返します。

//emlist[例][ruby]{
a = [1, 2, 3, 4]
result = []
a.combination(2) {|e| result << e} # => [1,2,3,4]
result #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
//}

@see Array#permutation, Array#repeated_combination...
<< 1 2 3 ... > >>