Class: Linear1::ArithmeticSequence
- Defined in:
- lib/linear1/arithmetic_sequence.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
(also: #to_a)
readonly
Returns the value of attribute a.
-
#common_difference ⇒ Object
(also: #d)
readonly
Returns the value of attribute common_difference.
Attributes inherited from Function
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*a) ⇒ ArithmeticSequence
constructor
A new instance of ArithmeticSequence.
-
#to_s ⇒ Object
Modified to count from zero instead of one.
Methods inherited from Function
#direct_variation?, #execute, #to_direct_variation, #to_slope_intercept, #x_intercept
Constructor Details
#initialize(*a) ⇒ ArithmeticSequence
Returns a new instance of ArithmeticSequence.
12 13 14 15 16 17 18 19 20 |
# File 'lib/linear1/arithmetic_sequence.rb', line 12 def initialize *a i = 0 while i < a.length - 2 raise ArgumentError, "Elements must have a common difference" unless a[i+1] - a[i] == a[i+2] - a[i+1] i += 1 end @common_difference, @a = display_num(a[1]) - display_num(a[0]), a super @common_difference, @a[0] end |
Instance Attribute Details
#a ⇒ Object (readonly) Also known as: to_a
Returns the value of attribute a.
7 8 9 |
# File 'lib/linear1/arithmetic_sequence.rb', line 7 def a @a end |
#common_difference ⇒ Object (readonly) Also known as: d
Returns the value of attribute common_difference.
7 8 9 |
# File 'lib/linear1/arithmetic_sequence.rb', line 7 def common_difference @common_difference end |
Class Method Details
.find(index) ⇒ Object
4 5 6 |
# File 'lib/linear1/arithmetic_sequence.rb', line 4 def self.find index new *(ARGV[index..(ARGV.length - 1)]) end |
Instance Method Details
#to_s ⇒ Object
Modified to count from zero instead of one
21 22 23 |
# File 'lib/linear1/arithmetic_sequence.rb', line 21 def to_s # Modified to count from zero instead of one "a[n] = #{a[0]} + #{idx d}n" end |