Class: Basic101::Output
- Inherits:
-
Object
- Object
- Basic101::Output
- Defined in:
- lib/basic101/output.rb
Instance Method Summary collapse
- #echo(s) ⇒ Object
-
#initialize(file = $stdout) ⇒ Output
constructor
A new instance of Output.
- #isatty ⇒ Object
- #print(s) ⇒ Object
- #puts(s = '') ⇒ Object
- #tab_to(column) ⇒ Object
- #transcript=(transcript) ⇒ Object
Constructor Details
#initialize(file = $stdout) ⇒ Output
Returns a new instance of Output.
5 6 7 8 9 |
# File 'lib/basic101/output.rb', line 5 def initialize(file = $stdout) @file = file @chars_on_line = 0 @transcript = NullTranscript.new end |
Instance Method Details
#echo(s) ⇒ Object
23 24 25 |
# File 'lib/basic101/output.rb', line 23 def echo(s) write_string s, false end |
#isatty ⇒ Object
34 35 36 |
# File 'lib/basic101/output.rb', line 34 def isatty @file.isatty end |
#print(s) ⇒ Object
19 20 21 |
# File 'lib/basic101/output.rb', line 19 def print(s) write_string s, true end |
#puts(s = '') ⇒ Object
15 16 17 |
# File 'lib/basic101/output.rb', line 15 def puts(s = '') print s.to_s + "\n" end |
#tab_to(column) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/basic101/output.rb', line 27 def tab_to(column) column = [0, column].max spaces_needed = -> {column - @chars_on_line} return if spaces_needed.call < 0 print ' ' * spaces_needed.call end |
#transcript=(transcript) ⇒ Object
11 12 13 |
# File 'lib/basic101/output.rb', line 11 def transcript=(transcript) @transcript = transcript end |