Class: Code
- Inherits:
-
Object
- Object
- Code
- Defined in:
- lib/ruby_rtl/code.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #<<(thing) ⇒ Object
- #finalize ⇒ Object
-
#initialize(str = nil) ⇒ Code
constructor
A new instance of Code.
- #newline ⇒ Object
- #save_as(filename, verbose = true, sep = "\n") ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ Code
Returns a new instance of Code.
5 6 7 8 9 |
# File 'lib/ruby_rtl/code.rb', line 5 def initialize str=nil @lines=[] (@lines << str) if str @indent=0 end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
3 4 5 |
# File 'lib/ruby_rtl/code.rb', line 3 def indent @indent end |
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/ruby_rtl/code.rb', line 3 def lines @lines end |
Instance Method Details
#<<(thing) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_rtl/code.rb', line 15 def <<(thing) if (code=thing).is_a? Code code.lines.each do |line| @lines << " "*@indent+line.to_s end elsif thing.is_a? Array thing.each do |kode| @lines << kode end elsif thing.nil? else @lines << " "*@indent+thing.to_s end end |
#finalize ⇒ Object
30 31 32 33 |
# File 'lib/ruby_rtl/code.rb', line 30 def finalize return @lines.join("\n") if @lines.any? "" end |
#newline ⇒ Object
35 36 37 |
# File 'lib/ruby_rtl/code.rb', line 35 def newline @lines << " " end |
#save_as(filename, verbose = true, sep = "\n") ⇒ Object
39 40 41 42 43 |
# File 'lib/ruby_rtl/code.rb', line 39 def save_as filename,verbose=true,sep="\n" str=self.finalize File.open(filename,'w'){|f| f.puts(str)} return filename end |
#size ⇒ Object
11 12 13 |
# File 'lib/ruby_rtl/code.rb', line 11 def size @lines.size end |