Class: Linear::Standard

Inherits:
Function
  • Object
show all
Defined in:
lib/linear/standard.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c) ⇒ Standard

Returns a new instance of Standard



11
12
13
14
# File 'lib/linear/standard.rb', line 11

def initialize a, b, c
	@a, @b, @c = a.to_f, b.to_f, c.to_f
	super @c / @b / @a, @c / @b
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a



4
5
6
# File 'lib/linear/standard.rb', line 4

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b



4
5
6
# File 'lib/linear/standard.rb', line 4

def b
  @b
end

#cObject (readonly)

Returns the value of attribute c



4
5
6
# File 'lib/linear/standard.rb', line 4

def c
  @c
end

Class Method Details

.find(index) ⇒ Object



6
7
8
9
10
# File 'lib/linear/standard.rb', line 6

def self.find index
	array = ARGV[index..(index + 2)]
	$equation_index = index + 3
	return new array[0], array[1], array[2]
end

Instance Method Details

#add(int) ⇒ Object



28
29
30
# File 'lib/linear/standard.rb', line 28

def add int
	new @a + int, @b + int, @c + int
end

#add!(int) ⇒ Object



23
24
25
26
27
# File 'lib/linear/standard.rb', line 23

def add! int
	@a += int
	@b += int
	@c += int
end

#multiply(int) ⇒ Object



15
16
17
# File 'lib/linear/standard.rb', line 15

def multiply int
	new @a * int, @b * int, @c * int
end

#multiply!(factor) ⇒ Object



18
19
20
21
22
# File 'lib/linear/standard.rb', line 18

def multiply! factor
	@a *= factor
	@b *= factor
	@c *= factor
end

#to_sObject



31
32
33
# File 'lib/linear/standard.rb', line 31

def to_s
	"#{idx a}x + #{idx b} = #{c}"
end

#to_slope_interceptObject Also known as: to_si



34
35
36
37
# File 'lib/linear/standard.rb', line 34

def to_slope_intercept
	require "linear/slope_intercept"
	SlopeIntercept.new slope, y_intercept
end