Class: CLIntegracon::LazyStringProxy
- Inherits:
-
Object
- Object
- CLIntegracon::LazyStringProxy
- Defined in:
- lib/CLIntegracon/formatter.rb
Overview
A LazyStringProxy returns a LazyString for each call, which delegates the call as soon as the result is needed to the underlying formatter.
Instance Attribute Summary collapse
-
#formatter ⇒ Formatter
readonly
The formatter used to build the string.
Instance Method Summary collapse
-
#initialize(formatter) ⇒ LazyStringProxy
constructor
Initialize a LazyStringProxy, which returns for each call to an underlying formatter a new LazyString, whose #to_s method will evaluate to the result of the original call delegated to the formatter.
-
#method_missing(method, *args, &block) ⇒ #to_s
Remember the call delegated to #formatter in a closure on an anonymous object, defined as method :to_s.
-
#respond_to?(method) ⇒ Bool
Respond to all methods, which are beginning with ‘describe_` to which the #formatter also responds.
Constructor Details
#initialize(formatter) ⇒ LazyStringProxy
Initialize a LazyStringProxy, which returns for each call to an underlying formatter a new LazyString, whose #to_s method will evaluate to the result of the original call delegated to the formatter.
50 51 52 |
# File 'lib/CLIntegracon/formatter.rb', line 50 def initialize(formatter) @formatter = formatter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ #to_s
Remember the call delegated to #formatter in a closure on an anonymous object, defined as method :to_s.
59 60 61 62 63 |
# File 'lib/CLIntegracon/formatter.rb', line 59 def method_missing(method, *args, &block) return LazyString.new do @formatter.send(method, *args, &block) end end |
Instance Attribute Details
#formatter ⇒ Formatter (readonly)
Returns the formatter used to build the string.
41 42 43 |
# File 'lib/CLIntegracon/formatter.rb', line 41 def formatter @formatter end |
Instance Method Details
#respond_to?(method) ⇒ Bool
Respond to all methods, which are beginning with ‘describe_` to which the #formatter also responds.
70 71 72 73 74 75 76 |
# File 'lib/CLIntegracon/formatter.rb', line 70 def respond_to?(method) if /^describe_/.match(method.to_s) && @formatter.respond_to?(method) true else super end end |