[#39845] Re: [ruby-cvs:33238] Ruby:r26022 (trunk): * marshal.c (w_object): dump instance variables when using — Tanaka Akira <akr@...>
2009/12/5 <nobu@ruby-lang.org>:
3 messages
2009/12/06
[#39846] [Bug #2447] reduce GC pressure by symbol table without String instance — Yusuke Endoh <redmine@...>
Bug #2447: reduce GC pressure by symbol table without String instance
5 messages
2009/12/06
[#39847] stable find.rb — Tanaka Akira <akr@...>
ディレクトリを再帰的にたどった結果を比較することがあったのですが、
5 messages
2009/12/06
[#39851] Time.now + str と #to_r — Yukihiro Matsumoto <matz@...>
まつもと ゆきひろです
9 messages
2009/12/07
[#39852] Re: Time.now + str と #to_r
— "NARUSE, Yui" <naruse@...>
2009/12/07
成瀬です。
[#39855] [RubySpec #2460] RubySpecでFiberのSpecがおちる — 三村 益隆 <redmine@...>
RubySpec #2460: RubySpecでFiberのSpecがおちる
4 messages
2009/12/08
[#39863] [Feature #2471] want to choose a GC algorithm — _ wanabe <redmine@...>
Feature #2471: want to choose a GC algorithm
8 messages
2009/12/09
[#39874] faster Enumerator#each by rb_block_call with current block — Yusuke ENDOH <mame@...>
遠藤です。
7 messages
2009/12/13
[#39894] Re: faster Enumerator#each by rb_block_call with current block
— Yukihiro Matsumoto <matz@...>
2009/12/19
まつもと ゆきひろです
[#39897] Re: faster Enumerator#each by rb_block_call with current block
— Yusuke ENDOH <mame@...>
2009/12/20
遠藤です。
[#39912] [Bug #2522] Segmentation Fault is occurred on r26158 by running rubyspec — Kenta Murata <redmine@...>
Bug #2522: Segmentation Fault is occurred on r26158 by running rubyspec
4 messages
2009/12/23
[ruby-dev:39927] [Bug #2533] sample/occur2.rb is old-fashioned
From:
Yuki Sonoda <redmine@...>
Date:
2009-12-27 00:25:56 UTC
List:
ruby-dev #39927
Bug #2533: sample/occur2.rb is old-fashioned
http://redmine.ruby-lang.org/issues/show/2533
起票者: Yuki Sonoda
ステータス: Open, 優先度: Normal
担当者: Yukihiro Matsumoto, Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2009-12-24 trunk 26168) [i386-darwin9.8.0]
Kernel#splitが無くなったことでsample/occur2.rbが動かなくなっていたのでr26180で修正しました。
それにしてもsample/occur2.rbは、今から見るとあまり良くないように思えます。
暗黙の変数を使うあたりがあまり現代Ruby的でなく、無意味にNil#+(Integer)のNameErrorでキーの不在をフォローしているのが教育上好ましくないと思います。
例外を使ってみるとか、何らかの意図があったんでしょうか。
現代語としては次のようになるのが自然ではないかと思いますが、いかがでしょうか。もし良ければ差し替えたいと思います。
diff --git a/sample/occur2.rb b/sample/occur2.rb
index 22cf520..ca87d0d 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
----------------------------------------
http://redmine.ruby-lang.org