Class: EquationValue

Inherits:
Equation show all
Defined in:
lib/symcalc.rb

Overview

Implements basic numeric values as the Equation class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Equation

#*, #**, #+, #-, #/, #__simplify__, #__sub__, #coerce, #derivative, #eval, #inspect, #simplify, #sub, #to_s

Constructor Details

#initialize(value) ⇒ EquationValue

Returns a new instance of EquationValue.



243
244
245
# File 'lib/symcalc.rb', line 243

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



241
242
243
# File 'lib/symcalc.rb', line 241

def value
  @value
end

Instance Method Details

#==(value) ⇒ Object



263
264
265
# File 'lib/symcalc.rb', line 263

def ==(value)
  @value == value
end

#__derivative__(variable: nil) ⇒ Object



259
260
261
# File 'lib/symcalc.rb', line 259

def __derivative__ variable: nil
  return EquationValue.new 0
end

#__eval__(var_hash) ⇒ Object



251
252
253
254
255
256
257
# File 'lib/symcalc.rb', line 251

def __eval__ var_hash
  if @value.is_a? Integer
    return @value.to_f
  else
    return @value
  end
end

#__get_m_elements__(var_hash) ⇒ Object



276
277
278
279
280
281
282
283
# File 'lib/symcalc.rb', line 276

def __get_m_elements__ var_hash
  if var_hash.keys.include? self
    var_hash[self] = var_hash[self] + 1
  else
    var_hash[self] = 1
  end
  return var_hash
end

#all_variablesObject



286
287
288
# File 'lib/symcalc.rb', line 286

def all_variables
  []
end

#displayObject



247
248
249
# File 'lib/symcalc.rb', line 247

def display
  return @value.to_s
end

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


271
272
273
274
# File 'lib/symcalc.rb', line 271

def eql? obj
  return false if !obj.is_a? EquationValue
  return obj.value == @value
end

#hashObject



267
268
269
# File 'lib/symcalc.rb', line 267

def hash
  1111000 + @value
end