Class: MathViz::Constant

Inherits:
Term show all
Defined in:
lib/mathviz.rb

Overview

A simple number.

Also identifies the number as true constant, which affects nodes display style, so that opportunities for constant-folding can be idenified.

Direct Known Subclasses

Input

Instance Attribute Summary

Attributes inherited from Term

#name

Instance Method Summary collapse

Methods inherited from Term

binop, #color, #data, #label, list_terms, name_terms!, #style, #to_dot, #to_i, #to_s, unop

Methods included from Measured

#per, #unit, #with_units

Methods included from Units::Class

#included, #new_units

Constructor Details

#initialize(a) ⇒ Constant

wraps a primitive value



420
421
422
423
# File 'lib/mathviz.rb', line 420

def initialize(a)
  super()
  @a = a
end

Instance Method Details

#constant?Boolean

Returns:

  • (Boolean)


450
451
452
# File 'lib/mathviz.rb', line 450

def constant?
  true
end

#finite?Boolean

Forward to contained object

Returns:

  • (Boolean)


455
456
457
# File 'lib/mathviz.rb', line 455

def finite?
  @a.finite?
end

#longObject

Debugging method; string with both name and value



426
427
428
429
# File 'lib/mathviz.rb', line 426

def long
  n = @name && (@name + " = ")
  "(#{n}#{to_f})"
end

#shapeObject

Graphviz node shape



446
447
448
# File 'lib/mathviz.rb', line 446

def shape
  :plaintext
end

#to_fObject

Forward to contained object



432
433
434
# File 'lib/mathviz.rb', line 432

def to_f
  @a.to_f
end

#unitsObject

Returns the units of the contained object (if any) or else it’s own.



437
438
439
440
441
442
443
# File 'lib/mathviz.rb', line 437

def units
  if @a.respond_to? :units
    @a.units
  else
    super
  end
end