るりまサーチ

最速Rubyリファレンスマニュアル検索!
114件ヒット [1-100件を表示] (0.058秒)
トップページ > クエリ:nil[x] > クエリ:DATA[x] > クエリ:to_a[x]

別のキーワード

  1. net/imap data
  2. net/imap raw_data
  3. net/smtp data
  4. socket data
  5. smtp data

検索結果

<< 1 2 > >>

MatchData#to_a -> [String] (21113.0)

$&, $1, $2,... を格納した配列を返します。

...$&, $1, $2,... を格納した配列を返します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
//}

@see MatchData#captures...

MatchData#[](n) -> String | nil (3133.0)

n 番目の部分文字列を返します。

...)。n 番目の要素が存在しない時には nil を返します。

@param n 返す部分文字列のインデックスを指定します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~[0] # => "foobar"
p $~[1] #...
...=> "foo"
p $~[2] # => "bar"
p $~[3] # => nil (マッチしていない)
p $~[4] # => nil (範囲外)
p $~[-2] # => "bar"
//}...

MatchData#[](name) -> String | nil (3113.0)

name という名前付きグループにマッチした文字列を返します。

...m name 名前(シンボルか文字列)
@raise IndexError 指定した名前が正規表現内に含まれていない場合に発生します

//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:cents] # => "67"
/(?<alpha>[a-zA-Z]+)|(?<num>\d+)/.match("aZq")[:num] # => nil
//}...

MatchData#captures -> [String] (3036.0)

$1, $2, ... を格納した配列を返します。

...ます。

MatchData#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures...
...# => ["foo", "bar", nil]
//}

@see MatchData#to_a, MatchData#named_captures...

MatchData#values_at(*index) -> [String] (3030.0)

正規表現中の n 番目の括弧にマッチした部分文字列の配列を返します。

....match("foobarbaz")
# same as m.to_a.values_at(...)
p m.values_at(0, 1, 2, 3, 4) # => ["foobarbaz", "foo", "bar", "baz", nil]
p m.values_at(-1, -2, -3, -4, -5) # => ["baz", "bar", "foo", nil, nil]

m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
m.to_a # => ["1 + 2"...

絞り込み条件を変える

MatchData#[](range) -> [String] (3008.0)

Range オブジェクト range の範囲にある要素からなる部分配列を返します。

Range オブジェクト range の範囲にある要素からなる部分配列を返します。

@param range start..end 範囲式。

//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0..2] # => ["foobar", "foo", "bar"]
//}

MatchData#[](start, length) -> [String] (3008.0)

start 番目から length 個の要素を含む部分配列を返します。

start 番目から length 個の要素を含む部分配列を返します。

//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0, 3] # => ["foobar", "foo", "bar"]
//}

@see Array#[]

Regexp#match(str, pos = 0) -> MatchData | nil (284.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。

省略可能な第二引数 pos を指定すると、マッチの開始位置を pos か...
...os を指定しても MatchData#offset 等の結果
には影響しません。つまり、
//emlist[][ruby]{
re.match(str[pos..-1])
//}

//emlist[][ruby]{
re.match(str, pos)
//}
は異なります。


ブロックを渡すと、マッチした場合に限り MatchData オブジェクトがブ...
...gexp.new("foo")

if reg.match("foobar")
puts "match"
end
# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil

p /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}

=== 便利な使いかた
正規表現にマッチし...

NEWS for Ruby 3.0.0 (72.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...*
* Can be sliced with Enumerator::ArithmeticSequence

//emlist[][ruby]{
dirty_data = ['--', 'data1', '--', 'data2', '--', 'data3']
dirty_data[(1..).step(2)] # take each second element
# => ["data1", "data2", "data3"]
//}

* Binding
* Binding#eval when called with one argument will use `"(...
...Set
* Update to set 1.0.0
* SortedSet has been removed for dependency and performance reasons.
* Set#join is added as a shorthand for `.to_a.join`.
* Set#<=> is added.
* Socket
* Add :connect_timeout to TCPSocket.new 17187
* Net::HTTP
* Net::HTTP#verify_hostname= and Net:...
...da's arity check.
* When writing to STDOUT redirected to a closed pipe, no broken pipe error message will be shown now. 14413
* `TRUE`/`FALSE`/`NIL` constants are no longer defined.
* Integer#zero? overrides Numeric#zero? for optimization. 16961
* Enumerable#grep and Enumerable#grep_v when...

メソッド呼び出し(super・ブロック付き・yield) (60.0)

メソッド呼び出し(super・ブロック付き・yield) * super * block * yield * block_arg * numbered_parameters * call_method

...なっています。


引数の直前に * がついている場合、その引数の値が展開されて
渡されます。展開はメソッド to_a を経由して行なわれます。つまり:

//emlist[][ruby]{
foo(1,*[2,3,4])
foo(1,*[])
foo(1,*[2,3,4],5)
foo(1,*[2,3,4],5,*[6])
//}

は、...
...メソッドを呼びだそうとすると、レシーバが nil の場合は
以下のように働きます。

* 引数の評価が行なわれない
* メソッド呼び出しが行われない
* nil を返す

レシーバが nil でない場合は通常のメソッド呼び出しが行わ...
...ブロック記法において | と | の間にはさまれた
変数(ブロックパラメータ)に代入されます。

例:

yield data


文法:

yield `(' [式 [`,' 式 ... ]] `)'
yield [式 [`,' 式 ... ]]

引数をブロックパラメータとして渡して...

絞り込み条件を変える

<< 1 2 > >>