Module: Nio::Formattable
- Included in:
- BigDecimal, Float, Integer, Rational
- Defined in:
- lib/nio/fmt.rb
Overview
This is a mix-in module to add formatting capabilities no numerical classes. A class that includes this module should provide the methods
- nio_write_neutral(fmt)
-
an instance method to write the value to a neutral numeral. The format is passed so that the base, for example, is available.
- nio_read_neutral(neutral)
-
a class method to create a value from a neutral numeral.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.append_features(mod) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#nio_round(fmt = Fmt.default) ⇒ Object
Round a formattable object according to the rounding mode and precision of a format.
-
#nio_write(fmt = Fmt.default) ⇒ Object
This is the method available in all formattable objects to format the value into a text string according to the optional format passed.
Class Method Details
.append_features(mod) ⇒ Object
:nodoc:
1182 1183 1184 1185 |
# File 'lib/nio/fmt.rb', line 1182 def self.append_features(mod) # :nodoc: super mod.extend ClassMethods end |
Instance Method Details
#nio_round(fmt = Fmt.default) ⇒ Object
Round a formattable object according to the rounding mode and precision of a format.
1176 1177 1178 1179 1180 |
# File 'lib/nio/fmt.rb', line 1176 def nio_round(fmt=Fmt.default) neutral = nio_write_neutral(fmt) fmt.round! neutral self.class.nio_read_neutral neutral end |
#nio_write(fmt = Fmt.default) ⇒ Object
This is the method available in all formattable objects to format the value into a text string according to the optional format passed.
1159 1160 1161 1162 |
# File 'lib/nio/fmt.rb', line 1159 def nio_write(fmt=Fmt.default) neutral = nio_write_neutral(fmt) fmt.nio_write_formatted(neutral) end |