From: Tietew Date: 2003-02-04T13:10:42+09:00 Subject: [ruby-list:37050] Re: String#each_byte On Tue, 4 Feb 2003 11:10:25 +0900 In article <20030204110409.9E7E.GGB03124@nifty.ne.jp> [[ruby-list:37047] String#each_byte] Take_tk wrote: > 具体的には、文字列をバイト単位で each_with_index や collect を簡単に使え > るようになるとうれしい。 こんなのを考えたことがあります。 module Enumerable class With include Enumerable def initialize(obj, meth) @obj = obj @meth = meth end def each(*args, &block) @obj.__send__ @meth, *args, &block end end def with(meth) With.new(self, meth) end def with_index With.new(self, :each_with_index) end end "abcde".with(:each_byte).collect # => [ ?a, ?b, ?c, ?d, ?e ] —[ Tietew ]—————————————————————————— メ : tietew@tietew.net / tietew@raug.net / tietew@masuclub.net ホペ: http://www.tietew.net/ Tietew Windows Lab. http://www.masuclub.net/ 鱒倶楽部 指紋: 26CB 71BB B595 09C4 0153 81C4 773C 963A D51B 8CAA