るりまサーチ

最速Rubyリファレンスマニュアル検索!
235件ヒット [1-100件を表示] (0.165秒)
トップページ > クエリ:i[x] > クエリ:h[x] > クエリ:String[x] > クエリ:Ruby[x] > クエリ:=~[x]

別のキーワード

  1. _builtin to_h
  2. struct to_h
  3. openstruct to_h
  4. ostruct to_h
  5. hash to_h

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

String#=~(other) -> Integer | nil (42348.0)

正規表現 other とのマッチを行います。 マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。

...正規表現 other とのマッチを行います。
マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。

other が正規表現でも文字列でもない場合は
other =~ self を行います。

このメソッドが実行され...
...が設定されます。

@param other 正規表現もしくは =~ メソッドを持つオブジェクト
@raise TypeError other が文字列の場合に発生します。

//emlist[例][ruby]{
p "string" =~ /str/ # => 0
p "string" =~ /not/ # => nil
p "abcfoo" =~ /foo/ # => 3
//}...

String#count(*chars) -> Integer (24212.0)

chars で指定された文字が文字列 self にいくつあるか数えます。

...chars で指定された文字が文字列 self にいくつあるか数えます。

検索する文字を示す引数 chars の形式は tr(1) と同じです。
つまり、「"a-c"」は文字 a から c を意味し、
「"^0-9"」のように文字列の先頭が「^」の場合は
指定文...
...えます。

@param chars 出現回数を数える文字のパターン

//emlist[例][ruby]{
p 'abcdefg'.count('c') # => 1
p '123456789'.count('2378') # => 4
p '123456789'.count('2-8', '^4-6') # => 4

# ファイルの行数を数える
n_lines = File.read("foo").count(...
..."\n")

# ファイルの末尾に改行コードがない場合にも対処する
buf = File.read("foo")
n_lines = buf.count("\n")
n_lines += 1 if /[^\n]\z/ =~ buf
# if /\n\z/ !~ buf だと空ファイルを 1 行として数えてしまうのでダメ
//}...

NilClass#=~(other) -> nil (21340.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 (18346.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#=~...

Readline.#readline(prompt = "", add_hist = false) -> String | nil (9413.0)

prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。

...列を返します。
このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。
何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、
ユーザからの入力がない場合は nil を返します。

本メソッドは...
...時には行内編集が可能で、vi モードと Emacs モードが用意されています。
デフォルトは Emacs モードです。

@param prompt カーソルの前に表示する文字列を指定します。デフォルトは""です。
@param add_hist 真ならば、入力した文字...
...フォルトは偽です。

@raise IOError 標準入力が tty でない、かつ、標準入力をクローズしている
(isatty(2) の errno が EBADF である。) 場合に発生します。

例:

require "readline"

i
nput = Readline.readline
(プロンプトなどは表...

絞り込み条件を変える

ruby 1.6 feature (6667.0)

ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。

...ruby 1.6 feature
ruby
version 1.6 は安定版です。この版での変更はバグ修正がメイン
になります。

((<stable-snapshot|URL:ftp://ftp.netlab.co.jp/pub/lang/ruby/stable-snapshot.tar.gz>)) は、日々更新される安定版の最新ソースです。

== 1.6.8 (2002-12-24) ->...
...した。

p "#{ "" }"

=> ruby 1.6.7 (2002-03-01) [i586-linux]
""

=> -:1: warning: bad substitution in string
ruby
1.6.7 (2002-09-12) [i586-linux]
"#{ }"

=> ruby 1.6.7 (2002-09-25) [i586-linux]
""

これは1.7から...
...す。
((<ruby-bugs-ja:PR#231>))

p Regexp.quote("#")

p /a#{Regexp.quote("#")}b/x =~ "ab"

=> -:3: warning: ambiguous first argument; make sure
ruby
1.6.7 (2002-03-01) [i586-linux]
"#"
0

=> -:3: warning: ambiguous first argument; m...

Regexp.last_match(nth) -> String | nil (6327.0)

整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。

...数 nth が 0 の場合、マッチした文字列を返します
($&)。それ以外では、nth 番目の括弧にマッチ
した部分文字列を返します($1,$2,...)。
対応する括弧がない場合やマッチしなかった場合には nil を返し
ます。

//emlist[例][ruby]{
/(.)...
...egexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match(0) # => "ab"
p Regexp.last_match(1) # => "a"
p Regexp.last_match(2) # => "b"
p Regexp.last_match(3) # => nil
//}

正規表現全体がマッチしなかった場合、引数なしの
Regexp.last_match はnil を返すた...
...ch[1] の形式では例外 NoMethodError が発生します。
対して、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 $! # => undefin...

Kernel$$LAST_PAREN_MATCH -> String | nil (6313.0)

$+ の別名

...uire "English"

r1 = Regexp.compile("<img src=(http:.+?)>")
r2 = Regexp.compile("<a href=(http|ftp).+?>(.+?)</a>")

while line = DATA.gets
[ r1, r2 ].each {|rep|
rep =~ line
p $+
}
end
__END__
<tr> <td><img src=http://localhost/a.jpg></td> <td>ikkou</td> <td><a href=h...
...ttp://localhost/link.html>link</a></td> </tr>
#enf of sample.rb

$ ruby sample.rb
"http://localhost/a.jpg"
"link"...

MatchData#post_match -> String (6313.0)

マッチした部分より後ろの文字列を返します($'と同じ)。

...マッチした部分より後ろの文字列を返します($'と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}

@see MatchData#pre_match...

MatchData#pre_match -> String (6313.0)

マッチした部分より前の文字列を返します($`と同じ)。

...マッチした部分より前の文字列を返します($`と同じ)。

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

@see MatchData#post_match...

絞り込み条件を変える

<< 1 2 3 > >>