るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

MatchData#end(n) -> Integer | nil (26247.0)

n 番目の部分文字列終端のオフセットを返します。

...数値。

@raise IndexError 範囲外の n を指定した場合に発生します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.end(0) # => 6
p $~.end(1) # => 3
p $~.end(2) # => 6
p $~.end(3) # => nil
p $~.end(4) # => `end': index 4 out of matches (IndexError)
//}

@see...

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

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

...合は、
要素とそのインデックスを繰り返すような
Enumerator を返します。

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

@param args イテ...
...each_with_index 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...

Array#each_index {|index| .... } -> self (14337.0)

各要素のインデックスに対してブロックを評価します。

...ックを評価します。

以下と同じです。

//emlist[例][ruby]{
(0 ... ary.size).each do |index|
# ....
end

//}

ブロックが与えられなかった場合は、自身と each_index から生成した
Enumerator オブジェクトを返します。

@see Array#each, Array#reverse_ea...

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

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

...合は、
要素とそのインデックスを繰り返すような
Enumerator を返します。

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

@param args イテ...
...each_with_index 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...

Array#each_index -> Enumerator (14137.0)

各要素のインデックスに対してブロックを評価します。

...ックを評価します。

以下と同じです。

//emlist[例][ruby]{
(0 ... ary.size).each do |index|
# ....
end

//}

ブロックが与えられなかった場合は、自身と each_index から生成した
Enumerator オブジェクトを返します。

@see Array#each, Array#reverse_ea...

絞り込み条件を変える

Array#each {|item| .... } -> self (8128.0)

各要素に対してブロックを評価します。

...してブロックを評価します。

ブロックが与えられなかった場合は、自身と each から生成した
Enumerator オブジェクトを返します。

//emlist[例][ruby]{
[1, 2, 3].each do |i|
puts i
end

#=> 1
# 2
# 3
//}


@see Array#each_index, Array#reverse_each...

Array#fetch(nth) {|nth| ... } -> object (8122.0)

nth 番目の要素を返します。

...返します。

Array#[] (nth) とは nth 番目の要素が存在しない場合の振舞いが異
なります。最初の形式では、例外 IndexError が発生します。
二番目の形式では、引数 ifnone を返します。
三番目の形式では、ブロックを評価した結果...
...@raise IndexError 引数 ifnone もブロックも指定しておらず、 nth 番目の要
素も存在しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end


p a....
...fetch(10, 999) #=> 999

result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}...

MatchData#begin(n) -> Integer | nil (8116.0)

n 番目の部分文字列先頭のオフセットを返します。

...

@raise IndexError 範囲外の 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...

Array#each -> Enumerator (8028.0)

各要素に対してブロックを評価します。

...してブロックを評価します。

ブロックが与えられなかった場合は、自身と each から生成した
Enumerator オブジェクトを返します。

//emlist[例][ruby]{
[1, 2, 3].each do |i|
puts i
end

#=> 1
# 2
# 3
//}


@see Array#each_index, Array#reverse_each...

Array#fetch(nth) -> object (8022.0)

nth 番目の要素を返します。

...返します。

Array#[] (nth) とは nth 番目の要素が存在しない場合の振舞いが異
なります。最初の形式では、例外 IndexError が発生します。
二番目の形式では、引数 ifnone を返します。
三番目の形式では、ブロックを評価した結果...
...@raise IndexError 引数 ifnone もブロックも指定しておらず、 nth 番目の要
素も存在しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end


p a....
...fetch(10, 999) #=> 999

result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}...

絞り込み条件を変える

<< 1 2 > >>