Class: Basic101::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/basic101/output.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = $stdout) ⇒ Output

Returns a new instance of Output.



7
8
9
10
11
# File 'lib/basic101/output.rb', line 7

def initialize(file = $stdout)
  @file = file
  @chars_on_line = 0
  @transcript = NullTranscript.new
end

Instance Method Details

#echo(s) ⇒ Object



25
26
27
# File 'lib/basic101/output.rb', line 25

def echo(s)
  write_string s, false
end

#isattyObject



36
37
38
# File 'lib/basic101/output.rb', line 36

def isatty
  @file.isatty
end


21
22
23
# File 'lib/basic101/output.rb', line 21

def print(s)
  write_string s, true
end

#puts(s = '') ⇒ Object



17
18
19
# File 'lib/basic101/output.rb', line 17

def puts(s = '')
  print s.to_s + "\n"
end

#tab_to(column) ⇒ Object



29
30
31
32
33
34
# File 'lib/basic101/output.rb', line 29

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



13
14
15
# File 'lib/basic101/output.rb', line 13

def transcript=(transcript)
  @transcript = transcript
end