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

#anonymous?, binop, #collapse, #color, #data, #generated?, #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



508
509
510
511
# File 'lib/mathviz.rb', line 508

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

Instance Method Details

#constant?Boolean

Returns:

  • (Boolean)


538
539
540
# File 'lib/mathviz.rb', line 538

def constant?
  true
end

#finite?Boolean

Forward to contained object

Returns:

  • (Boolean)


543
544
545
# File 'lib/mathviz.rb', line 543

def finite?
  @a.respond_to?(:finite?) ? @a.finite? : true
end

#longObject

Debugging method; string with both name and value



514
515
516
517
# File 'lib/mathviz.rb', line 514

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

#shapeObject

Graphviz node shape



534
535
536
# File 'lib/mathviz.rb', line 534

def shape
  :plaintext
end

#to_valueObject

Forward to contained object



520
521
522
# File 'lib/mathviz.rb', line 520

def to_value
  @a.to_value
end

#unitsObject

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



525
526
527
528
529
530
531
# File 'lib/mathviz.rb', line 525

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