Class: Hx::LazyContent
- Inherits:
-
Object
- Object
- Hx::LazyContent
- Defined in:
- lib/hx.rb
Instance Method Summary collapse
-
#initialize(&block) ⇒ LazyContent
constructor
A new instance of LazyContent.
- #to_json(*args) ⇒ Object
- #to_liquid(*args) ⇒ Object
- #to_s ⇒ Object
- #to_yaml(*args) ⇒ Object
Constructor Details
#initialize(&block) ⇒ LazyContent
Returns a new instance of LazyContent.
640 641 642 643 644 645 |
# File 'lib/hx.rb', line 640 def initialize(&block) raise ArgumentError, "No block given" unless block @lock = Mutex.new @content = nil @block = block end |
Instance Method Details
#to_json(*args) ⇒ Object
661 662 663 |
# File 'lib/hx.rb', line 661 def to_json(*args) to_s.to_json(*args) end |
#to_liquid(*args) ⇒ Object
665 666 667 |
# File 'lib/hx.rb', line 665 def to_liquid(*args) to_s.to_liquid(*args) end |
#to_s ⇒ Object
647 648 649 650 651 652 653 654 655 |
# File 'lib/hx.rb', line 647 def to_s @lock.synchronize do if @block @content = @block.call @block = nil end end @content end |
#to_yaml(*args) ⇒ Object
657 658 659 |
# File 'lib/hx.rb', line 657 def to_yaml(*args) to_s.to_yaml(*args) end |