diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | sample/occur2.rb | 11 |
2 files changed, 8 insertions, 7 deletions
@@ -1,3 +1,7 @@ +Mon Dec 28 18:13:26 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp> + + * sample/occur2.rb: reimplemented in modern style. [ruby-dev:39927]. + Mon Dec 28 17:19:37 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp> * tool/install-sh: correction by Hiro Asari. diff --git a/sample/occur2.rb b/sample/occur2.rb index 22cf52003a..ca87d0ddef 100644 --- a/sample/occur2.rb +++ b/sample/occur2.rb @@ -1,13 +1,10 @@ # word occurrence listing # usege: ruby occur2.rb file.. freq = {} -while gets() - for word in $_.split(/\W+/) - begin - freq[word] += 1 - rescue NameError - freq[word] = 1 - end +ARGF.each_line do |line| + for word in line.split(/\W+/) + freq[word] ||= 0 + freq[word] += 1 end end |