1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/sample/occur.rb
Kenichi Kamiya 8882986d97 Drop duplicated sample code (#2389) [ci skip]
* Drop duplicated sample code

* Drop another style sample

https://github.com/ruby/ruby/pull/2389#issuecomment-522489520

* Update sample list
2019-08-19 18:43:23 +09:00

12 lines
226 B
Ruby

# word occurrence listing
# usage: ruby occur.rb file..
freq = Hash.new(0)
while line = gets()
line.scan(/\w+/) do |word|
freq[word] += 1
end
end
for word in freq.keys.sort!
print word, " -- ", freq[word], "\n"
end