[#41278] [BUG:1.9] BINARY should not be ASCII-compatible — Yugui <yugui@...>

WXVndWkbJEIkRyQ5ISMbKEIKCgo+IBskQiRHISIkKiQqJGAkTSQzJDMkXiRHJE41RE9AJEclKyVQ

15 messages 2010/05/11

[#41407] [Bug #3339] win32ole test failure — Usaku NAKAMURA <redmine@...>

Bug #3339: win32ole test failure

20 messages 2010/05/25
[#41411] Re: [Bug #3339] win32ole test failure — Masaki Suketa <masaki.suketa@...> 2010/05/25

助田です。

[#41412] Re: [Bug #3339] win32ole test failure — "U.Nakamura" <usa@...> 2010/05/25

こんにちは、なかむら(う)です。

[ruby-dev:41345] Re: String#each_index の提案

From: "NARUSE, Yui" <naruse@...>
Date: 2010-05-19 01:24:09 UTC
List: ruby-dev #41345
成瀬です。

(2010/05/19 9:02), KISHIMOTO, Makoto wrote:
> きしもとです
> 
> String#each_index(と String#each_byteindex)というメソッドを提案します。
> Ruby で実装すると以下のようなメソッドです。
> 
> def each_index
>    unless block_given? then
>      Enumerator.new self, :each_index
>    else
>      i = 0
>      while i<  length do
>        yield i
>        i = i.succ
>      end
>      self
>    end
> end
> 
> 例えば以下のように使います。
> 
> def tr_succ!
>    each_index{|i|
>      self[i] = self[i].succ
>    }
> end
> 
> 同じことは each_char.with_index{|c, i| ...} でできますが、
> (どうせ c にアクセスするのでこちらのほうが有用かもしれませんが)
> each_index と書いたほうが、単純で意図が明確だと思います。

まず、備忘のために提案やバグ報告など、トラッキングの必要があるものは Redmine の
チケットとして頂けるとありがたいです。

次に提案自体ですが、この提案は String#each を削除した理由に反します。
(String の each 対象には line/character/codepoint/byte があるため)
(なお、1.8 での each 対象は line であった)

また、同じことは str.chars.with_index{|c, i| ...} でできかつこちらの方が明快ですし、
String#each を削除したことを考えればこちらの方が chars と明示している分よいと思います。

もっと言えば、このユースケースの場合 str.gsub(/./m){$&.succ} とした方が高速なのでは
ないかと思います。

-- 
NARUSE, Yui  <naruse@airemix.jp>

In This Thread