Class: Eye::Utils::AliveArray

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/eye/utils/alive_array.rb

Instance Method Summary collapse

Methods included from Enumerable

#pmap

Constructor Details

#initialize(arr = []) ⇒ AliveArray

Returns a new instance of AliveArray.


8
9
10
# File 'lib/eye/utils/alive_array.rb', line 8

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

Instance Method Details

#+(other) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'lib/eye/utils/alive_array.rb', line 36

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

#==(other) ⇒ Object


47
48
49
50
51
52
53
54
55
# File 'lib/eye/utils/alive_array.rb', line 47

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

#each(&block) ⇒ Object


12
13
14
# File 'lib/eye/utils/alive_array.rb', line 12

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

#full_sizeObject


20
21
22
# File 'lib/eye/utils/alive_array.rb', line 20

def full_size
  @arr.size
end

#pureObject


24
25
26
# File 'lib/eye/utils/alive_array.rb', line 24

def pure
  @arr
end

#sort(&block) ⇒ Object


32
33
34
# File 'lib/eye/utils/alive_array.rb', line 32

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

#sort_by(&block) ⇒ Object


28
29
30
# File 'lib/eye/utils/alive_array.rb', line 28

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

#to_aObject


16
17
18
# File 'lib/eye/utils/alive_array.rb', line 16

def to_a
  map{|x| x }
end