Class: MathViz::Constant
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
Instance Attribute Summary
Attributes inherited from Term
Instance Method Summary collapse
- #constant? ⇒ Boolean
-
#finite? ⇒ Boolean
Forward to contained object.
-
#initialize(a) ⇒ Constant
constructor
wraps a primitive value.
-
#long ⇒ Object
Debugging method; string with both name and value.
-
#shape ⇒ Object
Graphviz node shape.
-
#to_f ⇒ Object
Forward to contained object.
-
#units ⇒ Object
Returns the units of the contained object (if any) or else it’s own.
Methods inherited from Term
binop, #color, #data, #label, list_terms, name_terms!, #style, #to_dot, #to_i, #to_s, unop
Methods included from Measured
Methods included from Units::Class
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
450 451 452 |
# File 'lib/mathviz.rb', line 450 def constant? true end |
#finite? ⇒ Boolean
Forward to contained object
455 456 457 |
# File 'lib/mathviz.rb', line 455 def finite? @a.finite? end |
#long ⇒ Object
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 |
#shape ⇒ Object
Graphviz node shape
446 447 448 |
# File 'lib/mathviz.rb', line 446 def shape :plaintext end |
#to_f ⇒ Object
Forward to contained object
432 433 434 |
# File 'lib/mathviz.rb', line 432 def to_f @a.to_f end |
#units ⇒ Object
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 |