From 7844ea1c64a008983f03d76d96ea6c061cbf7cb6 Mon Sep 17 00:00:00 2001 From: yugui Date: Mon, 28 Dec 2009 09:14:14 +0000 Subject: [PATCH] * sample/occur2.rb: reimplemented in modern style. [ruby-dev:39927]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ sample/occur2.rb | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a91ea0f44..5598c3b186 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Dec 28 18:13:26 2009 Yuki Sonoda (Yugui) + + * sample/occur2.rb: reimplemented in modern style. [ruby-dev:39927]. + Mon Dec 28 17:19:37 2009 Yuki Sonoda (Yugui) * 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