class Markaby::Fragment

Every tag method in Markaby returns a Fragment. If any method gets called on the Fragment, the tag is removed from the Markaby stream and given back as a string. Usually the fragment is never used, though, and the stream stays intact.

For a more practical explanation, check out the README.

Public Class Methods

new(*args) click to toggle source
# File lib/markaby/builder.rb, line 238
def initialize(*args)
  @stream, @start, @length = args
  @transformed_stream = false
end

Public Instance Methods

to_s() click to toggle source
# File lib/markaby/builder.rb, line 247
def to_s
  transform_stream unless transformed_stream?
  @str.to_s
end
Also aliased as: to_str
to_str()
Alias for: to_s

Private Instance Methods

method_missing(...) click to toggle source
# File lib/markaby/builder.rb, line 255
def method_missing(...)
  transform_stream unless transformed_stream?
  @str.__send__(...)
end
respond_to_missing?(sym, *args) click to toggle source
# File lib/markaby/builder.rb, line 260
def respond_to_missing? sym, *args
  @str.respond_to? sym
end
transform_stream() click to toggle source
# File lib/markaby/builder.rb, line 264
def transform_stream
  @transformed_stream = true

  # We can't do @stream.slice!(@start, @length),
  # as it would invalidate the @starts and @lengths of other Fragment instances.
  @str = @stream[@start, @length].join.to_s
  @stream[@start, @length] = [nil] * @length
end
transformed_stream?() click to toggle source
# File lib/markaby/builder.rb, line 273
def transformed_stream?
  @transformed_stream
end