wc
This commit is contained in:
parent
021bd4f5ad
commit
eeb2006675
1 changed files with 24 additions and 0 deletions
24
wc.rb
Normal file
24
wc.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
def wc(file_path)
|
||||||
|
lines = 0
|
||||||
|
words = 0
|
||||||
|
bytes = 0
|
||||||
|
|
||||||
|
File.open(file_path) do |file|
|
||||||
|
file.each_line do |line|
|
||||||
|
lines += 1
|
||||||
|
words += line.split.size
|
||||||
|
bytes += line.bytesize
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[lines, words, bytes]
|
||||||
|
end
|
||||||
|
|
||||||
|
file_path = ARGV[0]
|
||||||
|
if file_path.nil?
|
||||||
|
puts 'ファイルパスがありません。'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
lines, words, bytes = wc(file_path)
|
||||||
|
puts "行数:#{lines}\n単語数:#{words}\nバイト数:#{bytes}\nファイルパス:#{file_path}"
|
Loading…
Reference in a new issue