Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/technical_graph/array.rb
Overview
Additional methods for array stackoverflow.com/questions/1341271/average-from-a-ruby-array
Instance Method Summary collapse
-
#clone_partial_w_fill(_from, _to) ⇒ Object
Create partial array and fill with border values if needed.
- #float_mean ⇒ Object
- #float_sum ⇒ Object
Instance Method Details
#clone_partial_w_fill(_from, _to) ⇒ Object
Create partial array and fill with border values if needed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/technical_graph/array.rb', line 16 def clone_partial_w_fill(_from, _to) part_array = Array.new # border = false (_from.._to).each do |current_i| # outside ranges if current_i < 0 part_array << self.first # border = true next end if self.size <= current_i part_array << self.last # border = true next end part_array << self[current_i] end return part_array end |
#float_mean ⇒ Object
11 12 13 |
# File 'lib/technical_graph/array.rb', line 11 def float_mean float_sum / size end |
#float_sum ⇒ Object
7 8 9 |
# File 'lib/technical_graph/array.rb', line 7 def float_sum inject(0.0) { |result, el| result + el } end |