Class: RubyOnRuby::RubyStream

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_on_ruby/ruby_stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = StringIO.new) ⇒ RubyStream

Returns a new instance of RubyStream.



7
8
9
# File 'lib/ruby_on_ruby/ruby_stream.rb', line 7

def initialize(stream = StringIO.new)
  @stream = stream
end

Instance Attribute Details

#streamObject

Returns the value of attribute stream.



5
6
7
# File 'lib/ruby_on_ruby/ruby_stream.rb', line 5

def stream
  @stream
end

Instance Method Details

#inputObject



11
12
13
14
15
16
17
18
19
# File 'lib/ruby_on_ruby/ruby_stream.rb', line 11

def input
  lambda do
    if stream.eof?
      nil
    else
      stream.read(1).ord
    end
  end
end

#outputObject



21
22
23
24
25
# File 'lib/ruby_on_ruby/ruby_stream.rb', line 21

def output
  lambda do |this, char|
    stream.print char.to_i.chr
  end
end