別のキーワード
モジュール
- Enumerable (12)
検索結果
先頭5件
-
String
# =~(other) -> Integer | nil (18143.0) -
正規表現 other とのマッチを行います。 マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。
...表現でも文字列でもない場合は
other =~ self を行います。
このメソッドが実行されると、組み込み変数 $~, $1, ...
にマッチに関する情報が設定されます。
@param other 正規表現もしくは =~ メソッドを持つオブジェクト
@raise......TypeError other が文字列の場合に発生します。
//emlist[例][ruby]{
p "string" =~ /str/ # => 0
p "string" =~ /not/ # => nil
p "abcfoo" =~ /foo/ # => 3
//}... -
Set
# delete _ if {|o| . . . } -> self (139.0) -
集合の各要素に対してブロックを実行し、その結果が真であるようなすべての 要素を削除します。
...delete_if は常に self を返します。
reject! は、要素が 1 つ以上削除されれば self を、1 つも削除されなければ
nil を返します。
//emlist[][ruby]{
require 'set'
s1 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
s1.delete_if {|str| str =~ /\.bak\z/}
p s1 # => #<S......et: {"hello.rb", "test.rb"}>
s2 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
p s2.reject! {|str| str =~ /\.bak\z/} # => #<Set: {"hello.rb", "test.rb"}>
p s2.reject! {|str| str =~ /\.o\z/} # => nil
//}
@see Enumerable#reject......ます。
delete_if は常に self を返します。
reject! は、要素が 1 つ以上削除されれば self を、1 つも削除されなければ
nil を返します。
//emlist[][ruby]{
s1 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
s1.delete_if {|str| str =~ /\.bak\z/}
p s1 # => #<Set: {......"hello.rb", "test.rb"}>
s2 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
p s2.reject! {|str| str =~ /\.bak\z/} # => #<Set: {"hello.rb", "test.rb"}>
p s2.reject! {|str| str =~ /\.o\z/} # => nil
//}
@see Enumerable#reject... -
Set
# reject! {|o| . . . } -> self | nil (139.0) -
集合の各要素に対してブロックを実行し、その結果が真であるようなすべての 要素を削除します。
...delete_if は常に self を返します。
reject! は、要素が 1 つ以上削除されれば self を、1 つも削除されなければ
nil を返します。
//emlist[][ruby]{
require 'set'
s1 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
s1.delete_if {|str| str =~ /\.bak\z/}
p s1 # => #<S......et: {"hello.rb", "test.rb"}>
s2 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
p s2.reject! {|str| str =~ /\.bak\z/} # => #<Set: {"hello.rb", "test.rb"}>
p s2.reject! {|str| str =~ /\.o\z/} # => nil
//}
@see Enumerable#reject......ます。
delete_if は常に self を返します。
reject! は、要素が 1 つ以上削除されれば self を、1 つも削除されなければ
nil を返します。
//emlist[][ruby]{
s1 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
s1.delete_if {|str| str =~ /\.bak\z/}
p s1 # => #<Set: {......"hello.rb", "test.rb"}>
s2 = Set['hello.rb', 'test.rb', 'hello.rb.bak']
p s2.reject! {|str| str =~ /\.bak\z/} # => #<Set: {"hello.rb", "test.rb"}>
p s2.reject! {|str| str =~ /\.o\z/} # => nil
//}
@see Enumerable#reject... -
Array
# keep _ if {|item| . . . } -> self (138.0) -
ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。
...[例][ruby]{
a = %w{ a b c d e f }
a.keep_if {|v| v =~ /[aeiou]/} # => ["a", "e"]
a # => ["a", "e"]
//}
keep_if は常に self を返しますが、Array#select! は要素が 1 つ以上削除されれば self を、
1 つも削除されなければ nil を返します。
//emlist[例][ruby]{
a......= %w{ a b c d e f }
a.keep_if {|v| v =~ /[a-z]/ } # => ["a", "b", "c", "d", "e", "f"]
a # => ["a", "b", "c", "d", "e", "f"]
//}
ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
@see Array#select!, Array#delete... -
Array
# filter! {|item| block } -> self | nil (131.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"]
//}
ブロックが与... -
Array
# select! {|item| block } -> self | nil (131.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"]
//}
ブロックが与... -
Array
# keep _ if -> Enumerator (38.0) -
ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。
...[例][ruby]{
a = %w{ a b c d e f }
a.keep_if {|v| v =~ /[aeiou]/} # => ["a", "e"]
a # => ["a", "e"]
//}
keep_if は常に self を返しますが、Array#select! は要素が 1 つ以上削除されれば self を、
1 つも削除されなければ nil を返します。
//emlist[例][ruby]{
a......= %w{ a b c d e f }
a.keep_if {|v| v =~ /[a-z]/ } # => ["a", "b", "c", "d", "e", "f"]
a # => ["a", "b", "c", "d", "e", "f"]
//}
ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
@see Array#select!, Array#delete... -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (34.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
...う名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返し......exError 正規表現中で定義されていない name を指定した場合に発生します。
//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.offset('year') # => [0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [... -
Array
# filter! -> Enumerator (31.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"]
//}
ブロックが与... -
Array
# select! -> Enumerator (31.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"]
//}
ブロックが与...