class Whitespace::Console
Constants
- LINE_SEPARATOR
Attributes
stdin[R]
stdout[R]
Public Class Methods
new(stdin: $stdin, stdout: $stdout)
click to toggle source
# File lib/whitespace/data_structures/console.rb, line 5 def initialize(stdin: $stdin, stdout: $stdout) @stdin = stdin @stdout = stdout end
Public Instance Methods
getc()
click to toggle source
# File lib/whitespace/data_structures/console.rb, line 24 def getc if c = stdin.getc unless Util.is_ascii?(c.ord) raise ArgumentError, "must be an ASCII character: #{c}" end c else raise ArgumentError, "must be an ASCII character: EOF" end end
getn()
click to toggle source
# File lib/whitespace/data_structures/console.rb, line 37 def getn input = "" loop do c = stdin.getc break if c.nil? input << c break if c == LINE_SEPARATOR end raise ArgumentError, "must be an integer: EOF" if input.empty? input = input.chomp(LINE_SEPARATOR) begin Integer input rescue raise ArgumentError, "must be an integer: #{input}" end end
printc(n)
click to toggle source
# File lib/whitespace/data_structures/console.rb, line 10 def printc(n) unless Util.is_ascii?(n) raise ArgumentError, "must be an ASCII character: #{n}" end stdout.print n.chr end
printn(n)
click to toggle source
# File lib/whitespace/data_structures/console.rb, line 17 def printn(n) unless Util.is_integer?(n) raise ArgumentError, "must be an integer: #{n}" end stdout.print n end