Class: Eye::Utils::AliveArray
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #each(&block) ⇒ Object
- #full_size ⇒ Object
-
#initialize(arr = []) ⇒ AliveArray
constructor
A new instance of AliveArray.
- #pure ⇒ Object
- #sort(&block) ⇒ Object
- #sort_by(&block) ⇒ Object
- #to_a ⇒ Object
Methods included from Enumerable
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_size ⇒ Object
20 21 22 |
# File 'lib/eye/utils/alive_array.rb', line 20 def full_size @arr.size end |
#pure ⇒ Object
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_a ⇒ Object
16 17 18 |
# File 'lib/eye/utils/alive_array.rb', line 16 def to_a map{|x| x } end |