種類
- インスタンスメソッド (392)
- 変数 (180)
- モジュール関数 (60)
- 特異メソッド (24)
- クラス (24)
ライブラリ
- ビルトイン (680)
クラス
モジュール
- Enumerable (24)
- Kernel (240)
キーワード
-
$ & (12) -
$ & # 39; (12) -
$ 1 (12) -
$ 10 (12) -
$ 11 (12) -
$ 2 (12) -
$ 3 (12) -
$ 4 (12) -
$ 5 (12) -
$ 6 (12) -
$ 7 (12) -
$ 8 (12) -
$ 9 (12) -
$ ` (12) -
$ ~ (12) - Lazy (12)
- Regexp (12)
- [] (48)
- begin (12)
- byteoffset (6)
- caller (36)
- captures (12)
- chunk (12)
- count (12)
- deconstruct (2)
-
delete
_ if (3) - end (12)
- filter! (14)
-
fixed
_ encoding? (12) -
keep
_ if (24) -
last
_ match (24) - length (12)
- loop (24)
-
method
_ missing (12) - offset (24)
-
post
_ match (12) -
pre
_ match (12) - reject! (3)
-
respond
_ to _ missing? (12) - select! (24)
- size (12)
-
slice
_ when (12) -
to
_ a (12) -
to
_ s (12) - ~ (12)
検索結果
先頭5件
-
Regexp
# =~(string) -> Integer | nil (26142.0) -
文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。
...しなかった
場合、あるいは string が nil の場合には nil を返
します。
//emlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p /foo/ =~ "afoo" # => 1
p /foo/ =~ "bar" # => nil
//}
組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定....../emlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p Regexp.last_match(0) # => "foo"
p /foo/ =~ "afoo" # => 1
p $~[0] # => "foo"
p /foo/ =~ "bar" # => nil
unless /foo/ === "bar"
puts "not match " # => not match
end
str = []
begin
/ugo/ =~ str
rescue TypeError
pr... -
String
# =~(other) -> Integer | nil (26130.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
//}... -
NilClass
# =~(other) -> nil (26128.0) -
右辺に正規表現オブジェクトを置いた正規表現マッチ obj =~ /RE/ をサポートするためのメソッドです。常に nil を返します。
...現マッチ obj =~ /RE/
をサポートするためのメソッドです。常に nil を返します。
@param other 任意のオブジェクトです。結果に影響しません。
//emlist[例][ruby]{
obj = 'regexp'
p(obj =~ /re/) #=> 0
obj = nil
p(obj =~ /re/) #=> nil
//}
@see String#=~... -
Object
# =~(other) -> nil (26128.0) -
右辺に正規表現オブジェクトを置いた正規表現マッチ obj =~ /RE/ をサポートするためのメソッドです。常に nil を返します。
...表現オブジェクトを置いた正規表現マッチ obj =~ /RE/
をサポートするためのメソッドです。常に nil を返します。
このメソッドは Ruby 2.6 から deprecated です。
この定義により、=~ が再定義されたオブジェクトでは正常にマッ......チを行い、
それ以外のものは nil を返すようになります。
@param other 任意のオブジェクトです。結果に影響しません。
//emlist[例][ruby]{
obj = 'regexp'
p(obj =~ /re/) #=> 0
obj = nil
p(obj =~ /re/) #=> nil
//}
@see String#=~......ッチ obj =~ /RE/
をサポートするためのメソッドです。常に nil を返します。
このメソッドは Ruby 2.6 から deprecated です。
意図せずに Array などに対して呼ばれた時にバグの原因になっていたため、
代わりに NilClass#=~ が定義さ......れています。
@param other 任意のオブジェクトです。結果に影響しません。
//emlist[例][ruby]{
obj = 'regexp'
p(obj =~ /re/) #=> 0
obj = nil
p(obj =~ /re/) #=> nil
//}
@see String#=~... -
Symbol
# =~(other) -> Integer | nil (26124.0) -
正規表現 other とのマッチを行います。
....to_s =~ other と同じです。)
@param other 比較対象のシンボルを指定します。
@return マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。
p :foo =~ /foo/ # => 0
p :foobar =~ /bar/ # => 3
p :foo =~ /bar....../ # => nil
@see String#=~... -
Regexp
# fixed _ encoding? -> bool (8054.0) -
正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
...# => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u{6666} a" # => 2
r =~ "\xa1\xa2 a".force_encoding("euc-jp") # => 2
r =~ "abc".force_encoding("euc-jp") # => 0
r = /a/u
r.fixed_encoding?......# => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 2
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # =......# => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 0
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # =... -
Set
# delete _ if {|o| . . . } -> self (8018.0) -
集合の各要素に対してブロックを実行し、その結果が真であるようなすべての 要素を削除します。
...st.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#reje... -
Set
# reject! {|o| . . . } -> self | nil (8018.0) -
集合の各要素に対してブロックを実行し、その結果が真であるようなすべての 要素を削除します。
...st.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#reje... -
Regexp
. last _ match(nth) -> String | nil (8013.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
...ます($1,$2,...)。
対応する括弧がない場合やマッチしなかった場合には nil を返し
ます。
//emlist[例][ruby]{
/(.)(.)/ =~ "ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match(0) # => "ab"
p Regexp.last_match(1) # => "a"
p Regexp.last_match(2......oMethodError が発生します。
対して、last_match(1) は nil を返します。
//emlist[例][ruby]{
str = "This is Regexp"
/That is Regexp/ =~ str
p Regexp.last_match # => nil
begin
p Regexp.last_match[1] # 例外が発生する
rescue
puts $! # => undefined method `[]' for nil:NilCla... -
Array
# keep _ if -> Enumerator (8012.0) -
ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。
...{|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... -
Array
# keep _ if {|item| . . . } -> self (8012.0) -
ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。
...{|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...