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.



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

#endObject

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.

Returns:

  • (Boolean)


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