Class: Code
- Inherits:
-
Object
- Object
- Code
- Defined in:
- lib/crokus/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
- #to_s ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ Code
Returns a new instance of Code.
5 6 7 8 9 |
# File 'lib/crokus/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/crokus/code.rb', line 3 def indent @indent end |
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/crokus/code.rb', line 3 def lines @lines end |
Instance Method Details
#<<(thing) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/crokus/code.rb', line 11 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
26 27 28 29 |
# File 'lib/crokus/code.rb', line 26 def finalize return @lines.join("\n") if @lines.any? "" end |
#newline ⇒ Object
35 36 37 |
# File 'lib/crokus/code.rb', line 35 def newline @lines << " " end |
#save_as(filename, verbose = true, sep = "\n") ⇒ Object
39 40 41 42 43 |
# File 'lib/crokus/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
45 46 47 |
# File 'lib/crokus/code.rb', line 45 def size @lines.size end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/crokus/code.rb', line 31 def to_s finalize end |