るりまサーチ

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

別のキーワード

  1. object yield_self
  2. _builtin yield_self
  3. _builtin self
  4. tracepoint self
  5. codeobject document_self

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

RubyVM::InstructionSequence#to_a -> Array (41136.0)

self の情報を 14 要素の配列にして返します。

...
self
の情報を 14 要素の配列にして返します。

命令シーケンスを以下の情報で表します。

: magic

データフォーマットを示す文字列。常に
"YARVInstructionSequence/SimpleDataFormat"。

: major_version

命令シーケンスのメジャーバー...
...命令シーケンスを構成する命令とオペランドの配列の配列。


//emlist[例][ruby]{
require 'pp'

iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
pp iseq.to_a
# ※ Ruby 2.5.0 での実行結果
# => ["YARVInstructionSequence/SimpleDataFormat",
# 2,
# 0,
# 1,
# {:arg_...

Array#to_a -> Array (18148.0)

self を返します。ただし、Array のサブクラスのインスタンスに対して呼ばれた時は、 自身を Array に変換したものを返します。

...
self
を返します。ただし、Array のサブクラスのインスタンスに対して呼ばれた時は、
自身を Array に変換したものを返します。

//emlist[例][ruby]{
class SubArray < Array; end
ary1 = Array([1, 2, 3, 4])
ary2 = SubArray([1, 2, 3, 4])

ary1.to_a # =>...
...[1, 2, 3, 4]
ary1.to_a.class # => Array

ary2.to_a # => [1, 2, 3, 4]
ary2.to_a.class # => Array
//}

@see Array#to_ary...

Set#to_a -> Array (18130.0)

self を配列に変換します。要素の順序は不定です。

...self を配列に変換します。要素の順序は不定です。

//emlist[][ruby]{
require 'set'
set = Set['hello', 'world']
p set.to_a # => ["hello", "world"]
//}...
...self を配列に変換します。要素の順序は不定です。

//emlist[][ruby]{
set = Set['hello', 'world']
p set.to_a # => ["hello", "world"]
//}...

Range#to_a -> Array (15160.0)

self を配列に変換します。

...
self
を配列に変換します。

@raise RangeError 終端のない Range オブジェクトを変換しようとしたときに発生します。

//emlist[例][ruby]{
p (5..0).to_a # => []
p (0..3).to_a # => [0, 1, 2, 3]
p ('a'..'c').to_a # => ["a", "b", "c"]
p (:a..:d).to_a # => [...
...:a, :b, :c, :d]

require 'date'
p (Date.new(1965, 4, 14) .. Date.new(1965, 4, 14)).to_a # => [#<Date: 1965-04-14 ((2438865j,0s,0n),+0s,2299161j)>]

(1..).to_a # RangeError: cannot convert endless range to an array
//}...

Array#to_ary -> self (6230.0)

self をそのまま返します。

...
self
をそのまま返します。

//emlist[例][ruby]{
class SubArray < Array; end
ary1 = Array([1, 2, 3, 4])
ary2 = SubArray([1, 2, 3, 4])

ary1.to_ary # => [1, 2, 3, 4]
ary1.to_ary.class # => Array

ary2.to_ary # => [1, 2, 3, 4]
ary2.to_ary.class # => SubArray
//}

@see Array#t...

絞り込み条件を変える

Array#permutation(n = self.length) { |p| block } -> self (258.0)

サイズ n の順列をすべて生成し,それを引数としてブロックを実行します。

...に発生します。

//emlist[例][ruby]{
a = [1, 2, 3]
a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutation(1).to_a #=> [[1],[2],[3]]
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1]...
...one permutation of length 0
a.permutation(4).to_a #=> [] : no permutations of length 4
//}

ブロックが与えられた場合、作成した配列の各要素を引数としてブロックを実
行して self を返します。

//emlist[例][ruby]{
a = [1, 2, 3]
result = []
a.permutation(2)...

Array#permutation(n = self.length) -> Enumerator (158.0)

サイズ n の順列をすべて生成し,それを引数としてブロックを実行します。

...に発生します。

//emlist[例][ruby]{
a = [1, 2, 3]
a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
a.permutation(1).to_a #=> [[1],[2],[3]]
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1]...
...one permutation of length 0
a.permutation(4).to_a #=> [] : no permutations of length 4
//}

ブロックが与えられた場合、作成した配列の各要素を引数としてブロックを実
行して self を返します。

//emlist[例][ruby]{
a = [1, 2, 3]
result = []
a.permutation(2)...

String#lines(rs = $/, chomp: false) {|line| ... } -> self (158.0)

文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)

...文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)

//emlist[][ruby]{
"aa\nbb\ncc\n".lines # => ["aa\n", "bb\n", "cc\n"]
//}

行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。
各 line には区...
...まり空行で分割します)。

chomp に true を指定すると、分割した各行の末尾から rs を取り除きます。

//emlist[][ruby]{
"hello\nworld\n".lines # => ["hello\n", "world\n"]
"hello\nworld\n".lines(chomp: true) # => ["hello", "world"]
//}

@param rs 行末...
...省略した場合は false を指定したとみなされます。

ブロックが指定された場合は String#each_line と同じように動作します。

Ruby
2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。

@see String#each_line...

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

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

...す。

//emlist[例][ruby]{
a = [1, 2, 3, 4]
a.combination(1).to_a #=> [[1],[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 combina...
...tion 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| resu...
<< 1 2 3 ... > >>