Module: Snow::EnumeratorSupport

Includes:
Enumerable
Included in:
Mat4, Mat4Array, Quat, QuatArray, Vec3, Vec3Array, Vec4, Vec4Array
Defined in:
lib/snow-math/to_a.rb

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/snow-math/to_a.rb', line 16

def each(&block)
  return to_enum(:each) unless block_given?
  (0 ... self.length).each {
    |index|
    yield(fetch(index))
  }
  self
end

#map(&block) ⇒ Object



34
35
36
37
# File 'lib/snow-math/to_a.rb', line 34

def map(&block)
  return to_enum(:map) unless block_given?
  self.dup.map!(&block)
end

#map!(&block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/snow-math/to_a.rb', line 25

def map!(&block)
  return to_enum(:map!) unless block_given?
  (0 ... self.length).each {
    |index|
    store(index, yield(fetch(index)))
  }
  self
end

#to_aObject



12
13
14
# File 'lib/snow-math/to_a.rb', line 12

def to_a
  (0 ... self.length).each.map { |index| fetch(index) }
end