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! ⇒ Object
- #sort_by(&block) ⇒ Object
- #to_a ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(arr = []) ⇒ AliveArray
Returns a new instance of AliveArray.
9 10 11 |
# File 'lib/eye/utils/alive_array.rb', line 9 def initialize(arr = []) @arr = arr end |
Instance Method Details
#+(other) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eye/utils/alive_array.rb', line 41 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
52 53 54 55 56 57 58 59 60 |
# File 'lib/eye/utils/alive_array.rb', line 52 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
13 14 15 |
# File 'lib/eye/utils/alive_array.rb', line 13 def each(&block) @arr.each { |elem| elem && elem.alive? && block[elem] } end |
#full_size ⇒ Object
21 22 23 |
# File 'lib/eye/utils/alive_array.rb', line 21 def full_size @arr.size end |
#pure ⇒ Object
25 26 27 |
# File 'lib/eye/utils/alive_array.rb', line 25 def pure @arr end |
#sort(&block) ⇒ Object
33 34 35 |
# File 'lib/eye/utils/alive_array.rb', line 33 def sort(&block) self.class.new super end |
#sort! ⇒ Object
37 38 39 |
# File 'lib/eye/utils/alive_array.rb', line 37 def sort! @arr.sort! end |
#sort_by(&block) ⇒ Object
29 30 31 |
# File 'lib/eye/utils/alive_array.rb', line 29 def sort_by(&block) self.class.new super end |
#to_a ⇒ Object
17 18 19 |
# File 'lib/eye/utils/alive_array.rb', line 17 def to_a map { |x| x } end |