class Miguel::Dumper
Class for dumping indented code blocks.
Public Class Methods
new( out = [], step = 2 )
click to toggle source
Create new dumper.
# File lib/miguel/dumper.rb, line 9 def initialize( out = [], step = 2 ) @out = out @indent = 0 @step = step end
Public Instance Methods
dump( line ) { || ... }
click to toggle source
Append given line/block to the output.
If block is given, it is automatically enclosed between do/end keywords and anything dumped within it is automatically indented.
# File lib/miguel/dumper.rb, line 26 def dump( line ) if block_given? dump "#{line} do" @indent += @step yield @indent -= @step dump "end" else @out << "#{' ' * @indent}#{line}\n" end self end
Also aliased as: <<
text()
click to toggle source
Get all output gathered so far as a string.
# File lib/miguel/dumper.rb, line 16 def text @out.join end
Also aliased as: to_s