Module: FormatEngine::AttrFormatter
- Defined in:
- lib/format_engine/attr_formatter.rb
Overview
This module adds the attr_formatter extension to a class.
Instance Method Summary collapse
-
#attr_formatter(method, library) ⇒ Object
Define a formatter for instances of the current class.
Instance Method Details
#attr_formatter(method, library) ⇒ Object
Define a formatter for instances of the current class.
Parameters
-
method - A symbol used to name the formatting method created by this method.
-
library - A hash of formatting rules that define the formatting
capabilities supported by this formatter.
Meta-effects
-
Creates a method (named after the symbol in method) that formats the
instance of the class. The created method takes one parameter:
Meta-method Parameters
-
spec_str - A format specification string with %x etc qualifiers.
Meta-method Returns
-
A formatted string
Returns
-
The format engine used by this method.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/format_engine/attr_formatter.rb', line 20 def attr_formatter(method, library) engine = Engine.new(library) #Create an instance method to do the formatting. define_method(method) do |spec_str| engine.do_format(self, spec_str) end engine end |