class Shaun::Number
A SHAUN number. SHAUN Numbers can be integers or floats indifferently. They can also have a unit
Example¶ ↑
5.2 km 44 kHz
Public Class Methods
new(value, unit = nil)
click to toggle source
Create a new number with its value and unit
# File lib/shaun.rb, line 80 def initialize(value, unit = nil) @value = value @unit = unit end
Public Instance Methods
pretty_print(pp)
click to toggle source
Pretty print the SHAUN value
# File lib/shaun.rb, line 105 def pretty_print(pp) pp.print_number self end
to_f()
click to toggle source
Cast the number to a bare Ruby Float
# File lib/shaun.rb, line 91 def to_f @value end
to_i()
click to toggle source
Cast the number to a bare Ruby Integer
# File lib/shaun.rb, line 86 def to_i @value end
to_s()
click to toggle source
Print the number to a String
# File lib/shaun.rb, line 96 def to_s if @unit "#{@value.to_s} #{@unit.to_s}" else "#{@value.to_s}" end end