別のキーワード
キーワード
- & (12)
- - (12)
- abbrev (12)
- bsearch (24)
-
bsearch
_ index (20) - collect! (24)
- combination (24)
- compact (12)
- compact! (12)
- concat (21)
-
delete
_ if (24) - difference (7)
- dig (10)
- each (24)
-
each
_ index (12) -
fetch
_ values (2) - fill (24)
- filter! (14)
- flatten (12)
- flatten! (12)
- insert (12)
-
keep
_ if (24) - map! (24)
- permutation (24)
- product (24)
- reject! (24)
-
repeated
_ combination (24) -
repeated
_ permutation (24) - replace (12)
-
reverse
_ each (24) - rotate! (12)
- sample (24)
- select! (24)
- sort (24)
- sort! (24)
-
sort
_ by! (24) -
to
_ a (12) -
to
_ ary (12) -
to
_ csv (12) -
to
_ h (19) - union (7)
- uniq (12)
- uniq! (12)
- unshift (12)
- zip (24)
- | (12)
検索結果
先頭5件
-
Array
# product(*lists) -> Array (12221.0) -
レシーバの配列と引数で与えられた配列(複数可)のそれぞれから要素を1 個ずつとって配列とし,それらのすべての配列を要素とする配列を返します。
...さのすべての積にな
ります。
@param lists 配列。複数指定可能。
//emlist[例][ruby]{
[1,2,3].product([4,5]) # => [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
[1,2].product([1,2]) # => [[1,1],[1,2],[2,1],[2,2]]
[1,2].product([3,4],[5,6]) # => [[1,3,5],[1,3,6],[1,4,5],[1,4,6......4,5],[2,4,6]]
[1,2].product() # => [[1],[2]]
[1,2].product([]) # => []
//}
ブロックが与えられた場合、作成した配列の各要素を引数としてブロックを実
行して self を返します。
//emlist[例][ruby]{
a = []
[1,2,3].product([4,5]) {|e| a << e}... -
Array
# repeated _ combination(n) -> Enumerator (12221.0) -
サイズ n の重複組み合わせをすべて生成し、それを引数としてブロックを実行 します。
...する Enumerator オブジェクトを返します。
@param n 生成される配列のサイズを整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
黙の型変換を試みます。
@raise TypeError 引数に......指定した場合に発生します。
//emlist[例][ruby]{
a = [1, 2, 3]
a.repeated_combination(1).to_a #=> [[1], [2], [3]]
a.repeated_combination(2).to_a #=> [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]
a.repeated_combination(3).to_a #=> [[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],......3]]
a.repeated_combination(4).to_a #=> [[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,2],[1,1,2,3],
# [1,1,3,3],[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],
# [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]]
a.repeated_combination(0).to_a... -
Array
# repeated _ permutation(n) -> Enumerator (12221.0) -
サイズ n の重複順列をすべて生成し,それを引数としてブロックを実行します。
...する Enumerator オブジェクトを返します。
@param n 生成する配列のサイズを整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
黙の型変換を試みます。
@raise TypeError 引数に整......mlist[例][ruby]{
a = [1, 2]
a.repeated_permutation(1).to_a #=> [[1], [2]]
a.repeated_permutation(2).to_a #=> [[1,1],[1,2],[2,1],[2,2]]
a.repeated_permutation(3).to_a #=> [[1,1,1],[1,1,2],[1,2,1],[1,2,2],
# [2,1,1],[2,1,2],[2,2,1],[2,2,2]]
a.repeated_permutation......).to_a #=> [[]] # one permutation of length 0
//}
ブロックが与えられた場合、作成した配列の各要素を引数としてブロックを実
行して self を返します。
//emlist[例][ruby]{
a = [1, 2]
result = []
a.repeated_permutation(3) {|e| result << e} # => [1,2]
result... -
Array
# sort _ by! -> Enumerator (12209.0) -
sort_by の破壊的バージョンです。
...sort_by の破壊的バージョンです。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
fruits = %w{apple pear fig}
fruits.sort_by! { |word| word.length }
fruits # => ["fig", "pear", "apple"]
//}
@see Enumerable#sort_by... -
Array
# concat(*other _ arrays) -> self (9311.0) -
other_arrays の要素を自身の末尾に破壊的に連結します。
...other_arrays の要素を自身の末尾に破壊的に連結します。
@param other_arrays 自身と連結したい配列を指定します。
//emlist[例][ruby]{
[ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
[ "a" ].concat( ["b"], ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
[ "a"......].concat #=> [ "a" ]
a = [ 1, 2, 3 ]
a.concat( [ 4, 5 ] )
a #=> [ 1, 2, 3, 4, 5 ]
a = [ 1, 2 ]
a.concat(a, a) #=> [1, 2, 1, 2, 1, 2]
//}
@see Array#+... -
Array
# concat(other) -> self (9311.0) -
配列 other を自身の末尾に破壊的に連結します。
...配列 other を自身の末尾に破壊的に連結します。
@param other 自身と連結したい配列を指定します。
//emlist[例][ruby]{
array = [1, 2]
a = [3, 4]
array.concat a
p array # => [1, 2, 3, 4]
p a # => [3, 4] # こちらは変わらない
/... -
Array
# to _ csv(**options) -> String (9272.0) -
CSV.generate_line(self, options) と同様です。
....generate_line(self, options) と同様です。
Array オブジェクトを 1 行の CSV 文字列に変換するためのショートカットです。
@param options CSV.generate_line と同様のオプションを指定します。
//emlist[][ruby]{
require 'csv'
p [1, 'Matz', :Ruby, Date.ne......w(1965, 4, 14)].to_csv # => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}
@see CSV.generate_line......to_csv # => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}
Ruby 3.0 (CSV 3.1.9) から、次のオプションが使えるようになりました。
//emlist[][ruby......]{
require 'csv'
puts [1, nil].to_csv # => 1,
puts [1, nil].to_csv(write_nil_value: "N/A") # => 1,N/A
puts [2, ""].to_csv # => 2,""
puts [2, ""].to_csv(write_empty_value: "BLANK") # => 2,BLANK
//}
@see CSV.generate_line... -
Array
# delete _ if -> Enumerator (9242.0) -
要素を順番にブロックに渡して評価し、その結果が真になった要素をすべて削除します。 delete_if は常に self を返しますが、reject! は要素が 1 つ以上削除されれば self を、 1 つも削除されなければ nil を返します。
...除します。
delete_if は常に self を返しますが、reject! は要素が 1 つ以上削除されれば self を、
1 つも削除されなければ nil を返します。
ブロックが与えられなかった場合は、自身と reject! から生成した
Enumerator オブジェクト......返された Enumerator オブジェクトの each メソッドには、
もとの配列に対して副作用があることに注意してください。
//emlist[例][ruby]{
a = [0, 1, 2, 3, 4, 5]
a.delete_if{|x| x % 2 == 0}
p a #=> [1, 3, 5]
a = [0, 1, 2, 3, 4, 5]
e = a.reject!
e.each{|i| i % 2......== 0}
p a #=> [1, 3, 5] もとの配列から削除されていることに注意。
//}
@see Array#select!, Array#keep_if... -
Array
# delete _ if {|x| . . . } -> self (9242.0) -
要素を順番にブロックに渡して評価し、その結果が真になった要素をすべて削除します。 delete_if は常に self を返しますが、reject! は要素が 1 つ以上削除されれば self を、 1 つも削除されなければ nil を返します。
...除します。
delete_if は常に self を返しますが、reject! は要素が 1 つ以上削除されれば self を、
1 つも削除されなければ nil を返します。
ブロックが与えられなかった場合は、自身と reject! から生成した
Enumerator オブジェクト......返された Enumerator オブジェクトの each メソッドには、
もとの配列に対して副作用があることに注意してください。
//emlist[例][ruby]{
a = [0, 1, 2, 3, 4, 5]
a.delete_if{|x| x % 2 == 0}
p a #=> [1, 3, 5]
a = [0, 1, 2, 3, 4, 5]
e = a.reject!
e.each{|i| i % 2......== 0}
p a #=> [1, 3, 5] もとの配列から削除されていることに注意。
//}
@see Array#select!, Array#keep_if... -
Array
# select! -> Enumerator (9226.0) -
ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。 変更があった場合は self を、 変更がなかった場合には nil を返します。
... self を、
変更がなかった場合には nil を返します。
//emlist[例][ruby]{
a = %w{ a b c d e f }
a.select! {|v| v =~ /[a-z]/ } # => nil
a # => ["a", "b", "c", "d", "e", "f"]
//}
ブロックが与えられなかった場合は、自身と select! から生成した
Enumerator オ......ブジェクトを返します。
@see Array#keep_if, Array#reject!...