Class: Linear1::SlopeIntercept

Inherits:
Function
  • Object
show all
Defined in:
lib/linear1/slope_intercept.rb

Direct Known Subclasses

DirectVariation

Instance Attribute Summary

Attributes inherited from Function

#power, #slope, #y_intercept

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#direct_variation?, display_num, #execute, #to_direct_variation, #to_function, #to_slope_intercept, #x_intercept

Constructor Details

#initialize(slope, y_intercept) ⇒ SlopeIntercept

Returns a new instance of SlopeIntercept



10
11
12
# File 'lib/linear1/slope_intercept.rb', line 10

def initialize(slope, y_intercept)
	super
end

Class Method Details

.try_convert(obj) ⇒ Object



4
5
6
7
8
9
# File 'lib/linear1/slope_intercept.rb', line 4

def self.try_convert obj
	for converter in %i[to_slope_intercept to_si]
		return obj.public_send converter if obj.respond_to? converter
	end
	fail TypeError, "Could not convert #{obj} to SlopeIntercept"
end

Instance Method Details

#to_psObject Also known as: to_point_slope



16
17
18
19
# File 'lib/linear1/slope_intercept.rb', line 16

def to_ps
	require "linear1/point_slope"
	PointSlope(0, @y_intercept, @slope)
end

#to_sObject



13
14
15
# File 'lib/linear1/slope_intercept.rb', line 13

def to_s
	super.sub "f(x)", "y"
end

#to_sfObject



21
22
23
24
# File 'lib/linear1/slope_intercept.rb', line 21

def to_sf
	require "linear1/standard"
	Standard.new(@slope, -1, -@y_intercept)
end