Class: LogicTools::Indenter
- Inherits:
-
Object
- Object
- LogicTools::Indenter
- Defined in:
- lib/logic_tools/traces.rb
Overview
Small class for indenting
Instance Method Summary collapse
-
#dec(value = 1) ⇒ Object
Decreases the indent level by
value
. -
#inc(value = 1) ⇒ Object
Increase the indent level by
value
. -
#initialize ⇒ Indenter
constructor
Creates a new indenter.
-
#to_s ⇒ Object
Converts to a string (generates the indent.).
Constructor Details
#initialize ⇒ Indenter
Creates a new indenter.
9 10 11 |
# File 'lib/logic_tools/traces.rb', line 9 def initialize @indent = 0 end |
Instance Method Details
#dec(value = 1) ⇒ Object
Decreases the indent level by value
.
NOTE:
* the indent level cannot be bellow 0.
* the value can be negative.
28 29 30 31 |
# File 'lib/logic_tools/traces.rb', line 28 def dec(value = 1) @indent -= value.to_i @indent = 0 if @indent < 0 end |
#inc(value = 1) ⇒ Object
Increase the indent level by value
.
NOTE:
* the indent level cannot be bellow 0.
* the value can be negative.
18 19 20 21 |
# File 'lib/logic_tools/traces.rb', line 18 def inc(value = 1) @indent += value.to_i @indent = 0 if @indent < 0 end |
#to_s ⇒ Object
Converts to a string (generates the indent.)
34 35 36 |
# File 'lib/logic_tools/traces.rb', line 34 def to_s return " " * @indent end |