summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--sample/occur2.rb11
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) <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