るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.022秒)
トップページ > クエリ:!~[x] > ライブラリ:ビルトイン[x] > クラス:String[x]

別のキーワード

  1. object !~
  2. _builtin !~
  3. !~ object
  4. !~ _builtin

検索結果

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

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

...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 行として数えてしまうのでダメ
//}...