Module: FStrings::Formats
- Defined in:
- lib/fstrings/formats.rb
Class Method Summary collapse
Class Method Details
.[]=(klass, formatter) ⇒ Object
11 12 13 |
# File 'lib/fstrings/formats.rb', line 11 def []=(klass, formatter) formats[klass] = formatter end |
.apply(val, format) ⇒ Object
19 20 21 |
# File 'lib/fstrings/formats.rb', line 19 def apply(val, format) self.for(val.class).call(val, format) end |
.for(klass) ⇒ Object
15 16 17 |
# File 'lib/fstrings/formats.rb', line 15 def for(klass) formats.select { |k,| klass <= k }.min_by { |k,| klass.ancestors.index(k) }.last end |
.formats ⇒ Object
7 8 9 |
# File 'lib/fstrings/formats.rb', line 7 def formats @formats ||= {} end |