[#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:41343] String#each_index の提案

From: "KISHIMOTO, Makoto" <ksmakoto@...4u.or.jp>
Date: 2010-05-19 00:02:04 UTC
List: ruby-dev #41343
きしもとです

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 と書いたほうが、単純で意図が明確だと思います。

In This Thread

Prev Next