BuilderObject

Build content programatically with Ruby and Ruby’s blocks.

Builders can use either an implict or explicit receiver. Explicit is the default. To use implicit pass the :implicit option to the constructor.

Implict building is more elegant in form, but it is not as functional because it makes it more difficult to refer to external references.

BuilderObject avoides metrhod name clashes by using Functor redirection. Unlike other implementations of the Builder patterns which append ’!’ to builder methods or simply use odd names to avoid clashes, BuilderObject routes all builder method vis the out method.

NOTE The name of this method (out) may be changed.

Methods
Public Class methods
builder()
# File lib/facets/more/builderobject.rb, line 47
  def self.builder
    @builder ||= Class.new
  end
builder_include( mod )
# File lib/facets/more/builderobject.rb, line 51
  def self.builder_include( mod )
    builder.class_eval { include mod }
  end
new()
# File lib/facets/more/builderobject.rb, line 55
  def initialize
    @stack = []
    @buffer = ''
  end
Public Instance methods
+( op, *args, &blk )
# File lib/facets/more/builderobject.rb, line 72
  def +( op, *args, &blk )
    @buffer << builder.send( op, *args, &blk )
  end
builder()
# File lib/facets/more/builderobject.rb, line 60
  def builder
    @builder ||= self.__class__.builder.new
  end
out( str=nil )
# File lib/facets/more/builderobject.rb, line 64
  def out( str=nil )
    if str
      @buffer << str
    else
      @builder_functor ||= Functor.new( &__method__(:+) )
    end
  end
to_s()
# File lib/facets/more/builderobject.rb, line 76
  def to_s
    @buffer
  end