Sha256: cd80f2febb68146570bfe070095c0976ef8dab2448dd28f2f5d247fbf34ac6f7

Contents?: true

Size: 892 Bytes

Versions: 5

Compression:

Stored size: 892 Bytes

Contents

class Eye::Utils::AliveArray
  extend Forwardable
  include Enumerable

  def_delegators :@arr, :[], :<<, :clear, :delete, :size, :empty?, :push,
                        :flatten, :present?, :uniq!, :select!

  def initialize(arr = [])
    @arr = arr
  end

  def each(&block)
    @arr.each{|elem| elem && elem.alive? && block[elem] }
  end

  def to_a
    map{|x| x }
  end

  def full_size
    @arr.size
  end

  def pure
    @arr
  end

  def sort_by(&block)
    self.class.new super
  end

  def +(other)
    if other.is_a?(Eye::Utils::AliveArray)
      @arr += other.pure
    elsif other.is_a?(Array)
      @arr += other
    else
      raise "Unexpected + #{other}"
    end
    self
  end

  def ==(other)
    if other.is_a?(Eye::Utils::AliveArray)
      @arr == other.pure
    elsif other.is_a?(Array)
      @arr == other
    else
      raise "Unexpected == #{other}"
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
reel-eye-0.5 lib/eye/utils/alive_array.rb
eye-0.5 lib/eye/utils/alive_array.rb
eye-0.4.2 lib/eye/utils/alive_array.rb
reel-eye-0.4.1 lib/eye/utils/alive_array.rb
eye-0.4.1 lib/eye/utils/alive_array.rb