Class: Oppen::Wadler::Wrap

Inherits:
Object
  • Object
show all
Defined in:
lib/wadler/print.rb

Overview

Helper class to allow conditional printing.

Instance Method Summary collapse

Constructor Details

#initialize(blk) ⇒ Wrap

Returns a new instance of Wrap.



838
839
840
841
# File 'lib/wadler/print.rb', line 838

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.



857
858
859
# File 'lib/wadler/print.rb', line 857

def method_missing(meth, ...)
  self.end.send(meth, ...)
end

Instance Method Details

#endObject

Flush.



852
853
854
# File 'lib/wadler/print.rb', line 852

def end
  @wrapper ? @wrapper.(@wrapped) : @wrapped.()
end

#respond_to_missing?(meth, include_private) ⇒ Boolean

To re-enable chaining.

Returns:

  • (Boolean)


862
863
864
# File 'lib/wadler/print.rb', line 862

def respond_to_missing?(meth, include_private)
  self.end.respond_to_missing?(meth, include_private)
end

#when(cond, &blk) ⇒ Object

Conditional.



844
845
846
847
848
849
# File 'lib/wadler/print.rb', line 844

def when(cond, &blk)
  if cond
    @wrapper = blk
  end
  self
end