Class: Daru::Accessors::ArrayWrapper
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/daru/accessors/array_wrapper.rb
Overview
Internal class for wrapping ruby array
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #==(other) ⇒ Object
- #[](*index) ⇒ Object
- #[]=(index, value) ⇒ Object
- #compact ⇒ Object
- #delete_at(index) ⇒ Object
- #dup ⇒ Object
- #each(&block) ⇒ Object
- #fill(*arg) ⇒ Object
- #index(*args, &block) ⇒ Object
-
#initialize(vector, context) ⇒ ArrayWrapper
constructor
A new instance of ArrayWrapper.
- #map!(&block) ⇒ Object
- #max ⇒ Object
- #mean ⇒ Object
- #min ⇒ Object
- #product ⇒ Object
- #sum ⇒ Object
- #to_a ⇒ Object
- #uniq ⇒ Object
Constructor Details
#initialize(vector, context) ⇒ ArrayWrapper
Returns a new instance of ArrayWrapper.
23 24 25 26 27 28 |
# File 'lib/daru/accessors/array_wrapper.rb', line 23 def initialize vector, context @data = vector.to_a @context = context set_size end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/daru/accessors/array_wrapper.rb', line 21 def data @data end |
#size ⇒ Object
Returns the value of attribute size.
20 21 22 |
# File 'lib/daru/accessors/array_wrapper.rb', line 20 def size @size end |
Instance Method Details
#<<(element) ⇒ Object
52 53 54 55 |
# File 'lib/daru/accessors/array_wrapper.rb', line 52 def << element @data << element set_size end |
#==(other) ⇒ Object
39 40 41 |
# File 'lib/daru/accessors/array_wrapper.rb', line 39 def == other @data == other end |
#[](*index) ⇒ Object
30 31 32 |
# File 'lib/daru/accessors/array_wrapper.rb', line 30 def [] *index @data[*index] end |
#[]=(index, value) ⇒ Object
34 35 36 37 |
# File 'lib/daru/accessors/array_wrapper.rb', line 34 def []= index, value @data[index] = value set_size end |
#compact ⇒ Object
74 75 76 |
# File 'lib/daru/accessors/array_wrapper.rb', line 74 def compact @data - Daru::MISSING_VALUES end |
#delete_at(index) ⇒ Object
43 44 45 46 |
# File 'lib/daru/accessors/array_wrapper.rb', line 43 def delete_at index @data.delete_at index set_size end |
#dup ⇒ Object
70 71 72 |
# File 'lib/daru/accessors/array_wrapper.rb', line 70 def dup ArrayWrapper.new @data.dup, @context end |
#each(&block) ⇒ Object
10 11 12 13 |
# File 'lib/daru/accessors/array_wrapper.rb', line 10 def each(&block) @data.each(&block) self end |
#fill(*arg) ⇒ Object
57 58 59 60 |
# File 'lib/daru/accessors/array_wrapper.rb', line 57 def fill(*arg) @data.fill(*arg) set_size end |
#index(*args, &block) ⇒ Object
48 49 50 |
# File 'lib/daru/accessors/array_wrapper.rb', line 48 def index *args, &block @data.index(*args, &block) end |
#map!(&block) ⇒ Object
15 16 17 18 |
# File 'lib/daru/accessors/array_wrapper.rb', line 15 def map!(&block) @data.map!(&block) self end |
#max ⇒ Object
89 90 91 |
# File 'lib/daru/accessors/array_wrapper.rb', line 89 def max compact.max end |
#mean ⇒ Object
78 79 80 81 82 83 |
# File 'lib/daru/accessors/array_wrapper.rb', line 78 def mean values_to_sum = compact return nil if values_to_sum.empty? sum = values_to_sum.inject :+ sum.quo(values_to_sum.size).to_f end |
#min ⇒ Object
93 94 95 |
# File 'lib/daru/accessors/array_wrapper.rb', line 93 def min compact.min end |
#product ⇒ Object
85 86 87 |
# File 'lib/daru/accessors/array_wrapper.rb', line 85 def product compact.inject :* end |
#sum ⇒ Object
97 98 99 |
# File 'lib/daru/accessors/array_wrapper.rb', line 97 def sum compact.inject :+ end |
#to_a ⇒ Object
66 67 68 |
# File 'lib/daru/accessors/array_wrapper.rb', line 66 def to_a @data end |
#uniq ⇒ Object
62 63 64 |
# File 'lib/daru/accessors/array_wrapper.rb', line 62 def uniq @data.uniq end |