Class: Handsoap::CodeWriter
- Inherits:
-
Object
- Object
- Handsoap::CodeWriter
- Defined in:
- lib/handsoap/compiler.rb
Overview
Used internally to generate Ruby source code
Instance Method Summary (collapse)
- - (Object) begin(text)
- - (Object) end(str = "end")
- - (Object) indent
-
- (CodeWriter) initialize
constructor
:nodoc: all.
- - (Object) puts(text = "")
- - (Object) to_s
- - (Object) unindent
Constructor Details
- (CodeWriter) initialize
:nodoc: all
6 7 8 9 |
# File 'lib/handsoap/compiler.rb', line 6 def initialize @buffer = "" @indentation = 0 end |
Instance Method Details
- (Object) begin(text)
11 12 13 14 |
# File 'lib/handsoap/compiler.rb', line 11 def begin(text) puts(text) indent end |
- (Object) end(str = "end")
16 17 18 19 |
# File 'lib/handsoap/compiler.rb', line 16 def end(str = "end") unindent puts(str) end |
- (Object) indent
26 27 28 |
# File 'lib/handsoap/compiler.rb', line 26 def indent @indentation = @indentation + 1 end |
- (Object) puts(text = "")
21 22 23 24 |
# File 'lib/handsoap/compiler.rb', line 21 def puts(text = "") @buffer << text.gsub(/^(.*)$/, (" " * @indentation) + "\\1") @buffer << "\n" # unless @buffer.match(/\n$/) end |
- (Object) to_s
34 35 36 |
# File 'lib/handsoap/compiler.rb', line 34 def to_s @buffer end |
- (Object) unindent
30 31 32 |
# File 'lib/handsoap/compiler.rb', line 30 def unindent @indentation = @indentation - 1 end |