Class: Lisp::Format::Directives::CharacterDirective
- Defined in:
- lib/carat/lisp-format.rb
Overview
Parent class for character outputting directives, such as ~% (NewLine), ~| (NewPage), and ~~ (Tilde), which output the same character a given number of times.
Instance Attribute Summary
Attributes inherited from Directive
Instance Method Summary collapse
-
#execute(state) ⇒ Object
Outputs the specific character (depending on the sub-classing directive) a given number of times.
-
#initialize(params, modifiers, top, pos, ch) ⇒ CharacterDirective
constructor
Create and set the character to use to
ch.
Methods inherited from Directive
Constructor Details
#initialize(params, modifiers, top, pos, ch) ⇒ CharacterDirective
Create and set the character to use to ch.
1267 1268 1269 1270 |
# File 'lib/carat/lisp-format.rb', line 1267 def initialize(params, modifiers, top, pos, ch) super params, modifiers, top, pos @ch = ch end |
Instance Method Details
#execute(state) ⇒ Object
Outputs the specific character (depending on the sub-classing directive) a given number of times. The full form is
~n[%|~]
with the following interpretations
n(1)-
number of times to output the specific character.
1278 1279 1280 1281 |
# File 'lib/carat/lisp-format.rb', line 1278 def execute(state) n = param(0, state, 1) state.output(@ch.chr * n) end |