Class: CLIntegracon::LazyString
- Inherits:
-
Object
- Object
- CLIntegracon::LazyString
- Defined in:
- lib/CLIntegracon/formatter.rb
Overview
A LazyString is constructed by a block, but only evaluated when needed
Instance Attribute Summary collapse
-
#proc ⇒ Proc
readonly
The closure which will be used to build the string.
Instance Method Summary collapse
-
#initialize(&block) ⇒ LazyString
constructor
Initialize a LazyString.
-
#to_str ⇒ String
(also: #to_s)
Calls the underlying proc to build the string.
Constructor Details
#initialize(&block) ⇒ LazyString
Initialize a LazyString
17 18 19 |
# File 'lib/CLIntegracon/formatter.rb', line 17 def initialize(&block) @proc = block end |
Instance Attribute Details
#proc ⇒ Proc (readonly)
Returns the closure which will be used to build the string.
10 11 12 |
# File 'lib/CLIntegracon/formatter.rb', line 10 def proc @proc end |
Instance Method Details
#to_str ⇒ String Also known as: to_s
Calls the underlying proc to build the string. The result will be memorized, so subsequent calls of this method will not cause that the proc will be called again.
27 28 29 |
# File 'lib/CLIntegracon/formatter.rb', line 27 def to_str @string ||= proc.call().to_s end |