class Warg::Console::IOProxy

Public Class Methods

new(io, console) click to toggle source
# File lib/warg.rb, line 198
def initialize(io, console)
  if io.is_a? IOProxy
    raise ArgumentError, "cannot nest `IOProxy' instances"
  end

  @io = io
  @console = console
  __setobj__ @io
end

Public Instance Methods

print(*texts) click to toggle source
puts(*texts) click to toggle source
# File lib/warg.rb, line 218
def puts(*texts)
  texts.each do |text|
    @io.puts text

    append_to_console_history text

    unless text.to_s.end_with?("\n")
      append_to_console_history "\n"
    end
  end

  nil
end
write(*texts) click to toggle source
# File lib/warg.rb, line 232
def write(*texts)
  texts.inject(0) do |count, text|
    @io.print text

    append_to_console_history(text)

    count + text.to_s.length
  end
end

Private Instance Methods

append_to_console_history(text) click to toggle source
# File lib/warg.rb, line 244
def append_to_console_history(text)
  content = Content.new(text, @console)
  @console.append_to_history(content)
end