31件ヒット
[1-31件を表示]
(0.024秒)
検索結果
先頭3件
-
String
# count(*chars) -> Integer (18144.0) -
chars で指定された文字が文字列 self にいくつあるか数えます。
...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("fo......o")
n_lines = buf.count("\n")
n_lines += 1 if /[^\n]\z/ =~ buf
# if /\n\z/ !~ buf だと空ファイルを 1 行として数えてしまうのでダメ
//}... -
Rake
:: FileList # egrep(pattern) {|filename , count , line| . . . } (3280.0) -
与えられたパターンをファイルリストから grep のように検索します。
...kefile での記載例とする
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_list.egrep(/line/) # => 7
file_list.egrep(/.*/) do |filename, count,......"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"
# => "filename = 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 (25.0) -
self と引数を合成した Proc を返します。
...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#>>...