Class: Oppen::Wadler::Wrap
- Inherits:
-
Object
- Object
- Oppen::Wadler::Wrap
- Defined in:
- lib/wadler/print.rb
Overview
Helper class to allow conditional printing.
Instance Method Summary collapse
-
#end ⇒ Object
Flush.
-
#initialize(blk) ⇒ Wrap
constructor
A new instance of Wrap.
-
#method_missing(meth) ⇒ Object
To re-enable chaining.
-
#respond_to_missing?(meth, include_private) ⇒ Boolean
To re-enable chaining.
-
#when(cond, &blk) ⇒ Object
Conditional.
Constructor Details
#initialize(blk) ⇒ Wrap
Returns a new instance of Wrap.
832 833 834 835 |
# File 'lib/wadler/print.rb', line 832 def initialize(blk) @wrapped = blk @wrapper = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
To re-enable chaining.
851 852 853 |
# File 'lib/wadler/print.rb', line 851 def method_missing(meth, ...) self.end.send(meth, ...) end |
Instance Method Details
#end ⇒ Object
Flush.
846 847 848 |
# File 'lib/wadler/print.rb', line 846 def end @wrapper ? @wrapper.(@wrapped) : @wrapped.() end |
#respond_to_missing?(meth, include_private) ⇒ Boolean
To re-enable chaining.
856 857 858 |
# File 'lib/wadler/print.rb', line 856 def respond_to_missing?(meth, include_private) self.end.respond_to_missing?(meth, include_private) end |
#when(cond, &blk) ⇒ Object
Conditional.
838 839 840 841 842 843 |
# File 'lib/wadler/print.rb', line 838 def when(cond, &blk) if cond @wrapper = blk end self end |