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
- #begin(text) ⇒ Object
- #end(str = "end") ⇒ Object
- #indent ⇒ Object
-
#initialize ⇒ CodeWriter
constructor
:nodoc: all.
- #puts(text = "") ⇒ Object
- #to_s ⇒ Object
- #unindent ⇒ Object
Constructor Details
#initialize ⇒ CodeWriter
:nodoc: all
6 7 8 9 |
# File 'lib/handsoap/compiler.rb', line 6 def initialize @buffer = "" @indentation = 0 end |
Instance Method Details
#begin(text) ⇒ Object
11 12 13 14 |
# File 'lib/handsoap/compiler.rb', line 11 def begin(text) puts(text) indent end |
#end(str = "end") ⇒ Object
16 17 18 19 |
# File 'lib/handsoap/compiler.rb', line 16 def end(str = "end") unindent puts(str) end |
#indent ⇒ Object
26 27 28 |
# File 'lib/handsoap/compiler.rb', line 26 def indent @indentation = @indentation + 1 end |
#puts(text = "") ⇒ Object
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 |
#to_s ⇒ Object
34 35 36 |
# File 'lib/handsoap/compiler.rb', line 34 def to_s @buffer end |
#unindent ⇒ Object
30 31 32 |
# File 'lib/handsoap/compiler.rb', line 30 def unindent @indentation = @indentation - 1 end |