Class: Warg::Console::IOProxy

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/warg.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, console) ⇒ IOProxy

Returns a new instance of IOProxy.


198
199
200
201
202
203
204
205
206
# 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

Instance Method Details


208
209
210
211
212
213
214
215
216
# File 'lib/warg.rb', line 208

def print(*texts)
  texts.each do |text|
    @io.print text

    append_to_console_history text
  end

  nil
end

#puts(*texts) ⇒ Object


218
219
220
221
222
223
224
225
226
227
228
229
230
# 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) ⇒ Object


232
233
234
235
236
237
238
239
240
# 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