るりまサーチ

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

別のキーワード

  1. bigdecimal/util to_d
  2. float to_d
  3. rsa d
  4. rsa d=
  5. matrix d

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

Enumerable#each_with_index(*args) {|item, index| ... } -> self (6202.0)

要素とそのインデックスをブロックに渡して繰り返します。

...ndex は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][ruby]{
[5, 10, 15].each_with_inde...
...x do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_index...

Enumerable#detect(ifnone = nil) -> Enumerator (6102.0)

要素に対してブロックを評価した値が真になった最初の要素を返します。

...初の 3 の倍数を探す
p [1, 2, 3, 4, 5].find {|i| i % 3 == 0 } # => 3
p [2, 2, 2, 2, 2].find {|i| i % 3 == 0 } # => nil

# ifnone の使用例
ifnone = proc { raise ArgumentError, "item not found" }
p [1, 2, 3, 4, 5].find(ifnone) {|i| i % 7 == 0 }
# ArgumentError: item not found
//}...

Enumerable#detect(ifnone = nil) {|item| ... } -> object (6102.0)

要素に対してブロックを評価した値が真になった最初の要素を返します。

...初の 3 の倍数を探す
p [1, 2, 3, 4, 5].find {|i| i % 3 == 0 } # => 3
p [2, 2, 2, 2, 2].find {|i| i % 3 == 0 } # => nil

# ifnone の使用例
ifnone = proc { raise ArgumentError, "item not found" }
p [1, 2, 3, 4, 5].find(ifnone) {|i| i % 7 == 0 }
# ArgumentError: item not found
//}...

Enumerable#drop(n) -> Array (6102.0)

Enumerable オブジェクトの先頭の n 要素を捨てて、 残りの要素を配列として返します。

...
Enumerable
オブジェクトの先頭の n 要素を捨てて、
残りの要素を配列として返します。

@param n 捨てる要素数。

//emlist[例][ruby]{
e = [1, 2, 3, 4, 5, 0].each
e.drop(3) # => [4, 5, 0]
//}

@see Array#drop...

Enumerable#drop_while -> Enumerator (6102.0)

ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。

...価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。

ブロックを指定しなかった場合は、Enumerator を返します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
//}...

絞り込み条件を変える

Enumerable#drop_while {|element| ... } -> Array (6102.0)

ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。

...価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。

ブロックを指定しなかった場合は、Enumerator を返します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
//}...

Enumerable#each_with_index(*args) -> Enumerator (6102.0)

要素とそのインデックスをブロックに渡して繰り返します。

...ndex は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][ruby]{
[5, 10, 15].each_with_inde...
...x do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_index...

Enumerable#find(ifnone = nil) -> Enumerator (6102.0)

要素に対してブロックを評価した値が真になった最初の要素を返します。

...初の 3 の倍数を探す
p [1, 2, 3, 4, 5].find {|i| i % 3 == 0 } # => 3
p [2, 2, 2, 2, 2].find {|i| i % 3 == 0 } # => nil

# ifnone の使用例
ifnone = proc { raise ArgumentError, "item not found" }
p [1, 2, 3, 4, 5].find(ifnone) {|i| i % 7 == 0 }
# ArgumentError: item not found
//}...

Enumerable#find(ifnone = nil) {|item| ... } -> object (6102.0)

要素に対してブロックを評価した値が真になった最初の要素を返します。

...初の 3 の倍数を探す
p [1, 2, 3, 4, 5].find {|i| i % 3 == 0 } # => 3
p [2, 2, 2, 2, 2].find {|i| i % 3 == 0 } # => nil

# ifnone の使用例
ifnone = proc { raise ArgumentError, "item not found" }
p [1, 2, 3, 4, 5].find(ifnone) {|i| i % 7 == 0 }
# ArgumentError: item not found
//}...
<< 1 2 3 ... > >>