[#49148] Ruby 1.9で、バイト長の部分文字列を作りたくて悩んでます — Daisuke Yokotsuka <yokots_d@...3-net.ne.jp>

はじめまして。横塚と申します。

16 messages 2013/01/29

[ruby-list:49166] Enumerator#+

From: 小田 利通 <oda@...>
Date: 2013-01-31 09:57:10 UTC
List: ruby-list #49166
小田と申します。

困っているとかでなく、単なる興味ですが、
Enumerator にインスタンスメソッド +@ がないのは、なぜでしょう?


class Enumerator
  def +(other)
    Enumerator.new {|y|
      self.each {|i| y<<i}
      other.each {|i| y<<i}
    }
  end
end

p ((0..2).each+(4..5).each).to_a  # => [0, 1, 2, 4, 5]
p ((0..6).step(2)+3.times).to_a   # => [0, 2, 4, 6, 0, 1, 2]

自然なメソッドで、あっても良さそうなのに、
ないのは何か理由があるのでしょうか。


In This Thread

Prev Next