1 |
class Eye::Utils::AliveArray |
16✔ |
2 |
extend Forwardable
|
16✔ |
3 |
include Enumerable
|
16✔ |
4 |
|
|
5 |
def_delegators :@arr, :[], :<<, :clear, :delete, :size, :empty?, :push, |
16✔ |
6 |
:flatten, :present?, :uniq!, :select! |
|
7 |
|
|
8 |
def initialize(arr = []) |
16✔ |
9 |
@arr = arr
|
1,370✔ |
10 |
end
|
|
11 |
|
|
12 |
def each(&block) |
16✔ |
13 |
@arr.each{|elem| elem && elem.alive? && block[elem] }
|
7,263✔ |
14 |
end
|
|
15 |
|
|
16 |
def to_a |
16✔ |
17 |
map{|x| x } |
3,114✔ |
18 |
end
|
|
19 |
|
|
20 |
def full_size |
16✔ |
21 |
@arr.size
|
4✔ |
22 |
end
|
|
23 |
|
|
24 |
def pure |
16✔ |
25 |
@arr
|
676✔ |
26 |
end
|
|
27 |
|
|
28 |
def sort_by(&block) |
16✔ |
29 |
self.class.new super |
620✔ |
30 |
end
|
|
31 |
|
|
32 |
def +(other) |
16✔ |
33 |
if other.is_a?(Eye::Utils::AliveArray) |
55✔ |
34 |
@arr += other.pure
|
9✔ |
35 |
elsif other.is_a?(Array) |
|
36 |
@arr += other
|
46✔ |
37 |
else
|
|
38 |
raise "Unexpected + #{other}"
|
× |
39 |
end
|
|
40 |
self
|
55✔ |
41 |
end
|
|
42 |
|
|
43 |
def ==(other) |
16✔ |
44 |
if other.is_a?(Eye::Utils::AliveArray) |
× |
45 |
@arr == other.pure
|
× |
46 |
elsif other.is_a?(Array) |
× |
47 |
@arr == other
|
× |
48 |
else
|
|
49 |
raise "Unexpected == #{other}"
|
× |
50 |
end
|
|
51 |
end
|
|
52 |
|
|
53 |
end
|