るりまサーチ

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

別のキーワード

  1. _builtin file?
  2. _builtin file
  3. file open
  4. base file
  5. file size

ライブラリ

キーワード

検索結果

String#pathmap(spec = nil) { ... } -> String (25.0)

与えられた書式指定文字列に応じてパス(自身)を変換します。

...ーセント自身を表します。


%d は数値のプレフィクスを取ることができます。

例:
'a/b/c/d/file.txt'.pathmap("%2d") # => 'a/b'
'a/b/c/d/file.txt'.pathmap("%-2d") # => 'c/d'

また、%d, %p, %f, %n, %x, %X には単純な文字列置換を行うための
置換...
...athmap("%{^src,bin}X.class")
#=> "bin/org/onestepback/proj/A.class"

置換文字列に '*' を指定した場合は、置換文字列を計算するためにブロックを評価します。

例:

"/path/to/file.TXT".pathmap("%X%{.*,*}x") { |ext| ext.downcase }
#=> "/path/to/file.txt"...

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

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

...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\...