るりまサーチ

最速Rubyリファレンスマニュアル検索!
31件ヒット [1-31件を表示] (0.131秒)

別のキーワード

  1. _builtin file?
  2. _builtin file
  3. file chown
  4. file truncate
  5. file chmod

ライブラリ

クラス

キーワード

検索結果

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

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

...

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

Rake::FileList#egrep(pattern) {|filename, count, line| ... } (3292.0)

与えられたパターンをファイルリストから grep のように検索します。

...@param pattern 正規表現を指定します。

//emlist[][ruby]{
# Rakefile での記載例とする

IO.write("sample1", "line1\nline2\nline3\n")
IO.write("sample2", "line1\nline2\nline3\nline4\n")

task default: :test_rake_app
task :test_rake_app do

file
_list = FileList.new('sample*')
file
...
...7

file
_list.egrep(/.*/) do |filename, count, line|
"filename = #{filename}, count = #{count}, line = #{line}"
end
end

# => "filename = sample1, count = 1, line = line1\n"
# => "filename = sample1, count = 2, line = line2\n"
# => "filename = sample1, count = 3, line = line3\n"
# => "filena...
...me = sample2, count = 1, line = line1\n"
# => "filename = sample2, count = 2, line = line2\n"
# => "filename = sample2, count = 3, line = line3\n"
# => "filename = sample2, count = 4, line = line4\n"
//}...

Proc#<<(callable) -> Proc (49.0)

self と引数を合成した Proc を返します。

...@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 + 3) * (3 + 3)
p (f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
clas...
...anner
def self.call(str)
str.scan(/\w+/)
end
end

File
.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@see Method#<<, Method#>>...