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.



199
200
201
202
203
204
205
206
207
# File 'lib/warg.rb', line 199

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



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

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

    append_to_console_history text
  end

  nil
end

#puts(*texts) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/warg.rb', line 219

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



233
234
235
236
237
238
239
240
241
# File 'lib/warg.rb', line 233

def write(*texts)
  texts.inject(0) do |count, text|
    @io.print text

    append_to_console_history(text)

    count + text.to_s.length
  end
end