Class: RubyOnRuby::RubyStream
- Inherits:
-
Object
- Object
- RubyOnRuby::RubyStream
- Defined in:
- lib/ruby_on_ruby/ruby_stream.rb
Instance Attribute Summary collapse
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(stream = StringIO.new) ⇒ RubyStream
constructor
A new instance of RubyStream.
- #input ⇒ Object
- #output ⇒ Object
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
#stream ⇒ Object
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
#input ⇒ Object
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 |
#output ⇒ Object
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 |