Class: RgGen::Core::Utility::CodeUtility::CodeBlock
- Defined in:
- lib/rggen/core/utility/code_utility/code_block.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
Instance Method Summary collapse
- #<<(rhs) ⇒ Object
- #eval_block(&block) ⇒ Object
-
#initialize(indent = 0) ⇒ CodeBlock
constructor
A new instance of CodeBlock.
- #last_line_empty? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(indent = 0) ⇒ CodeBlock
Returns a new instance of CodeBlock.
8 9 10 11 12 13 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 8 def initialize(indent = 0) @indent = indent @lines = [] add_line block_given? && yield(self) end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
15 16 17 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 15 def indent @indent end |
Instance Method Details
#<<(rhs) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 17 def <<(rhs) case rhs when String then push_string(rhs) when CodeBlock then push_code_block(rhs) when Array then rhs.inject(self, :<<) when code? then self << rhs.to_code else push_word(rhs) end end |
#eval_block(&block) ⇒ Object
40 41 42 43 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 40 def eval_block(&block) return unless block_given? block.arity.zero? ? self << yield : yield(self) end |
#last_line_empty? ⇒ Boolean
32 33 34 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 32 def last_line_empty? last_line.empty? end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/rggen/core/utility/code_utility/code_block.rb', line 36 def to_s @lines.map(&:to_s).each(&:rstrip!).join(newline) end |