Class: Liquidscript::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/liquidscript/buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Buffer

Returns a new instance of Buffer.



4
5
6
7
8
# File 'lib/liquidscript/buffer.rb', line 4

def initialize(*args)
  @_buf   = args
  @_cache = nil
  @_join  = ''
end

Instance Method Details

#append(*a) ⇒ Object Also known as: <<, push



10
11
12
13
14
# File 'lib/liquidscript/buffer.rb', line 10

def append(*a)
  @_cache = nil
  @_buf.push(*a)
  self
end

#block(str) ⇒ Object



16
17
18
# File 'lib/liquidscript/buffer.rb', line 16

def block(str)
  append str.gsub(/^[ \t]+/, '')
end

#inspectObject



33
34
35
# File 'lib/liquidscript/buffer.rb', line 33

def inspect
  to_s.inspect
end

#set_join!(to) ⇒ Object



20
21
22
# File 'lib/liquidscript/buffer.rb', line 20

def set_join!(to)
  @_join = to
end

#to_sObject



27
28
29
30
31
# File 'lib/liquidscript/buffer.rb', line 27

def to_s
  @_cache ||= begin
    @_buf.join @_join
  end
end