Module: Web::WritableIO
- Defined in:
- lib/web/stringio.rb
Overview
WritableIO uses << operator to add io style write, print, and puts methods
Instance Method Summary collapse
-
#print(*objects) ⇒ Object
writes objects to the output stream.
-
#puts(*objects) ⇒ Object
writes multiple lines to the output stream.
-
#write(object) ⇒ Object
writes object to output stream.
Instance Method Details
#print(*objects) ⇒ Object
writes objects to the output stream
10 11 12 13 14 15 16 17 |
# File 'lib/web/stringio.rb', line 10 def print( *objects ) if (objects.empty?) self << $_ else self << objects.collect{ |s| s.to_s }.join("") end if $\ then self << $\ end end |
#puts(*objects) ⇒ Object
writes multiple lines to the output stream
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/web/stringio.rb', line 20 def puts( *objects ) objects.flatten! self << objects.collect{ |s| s.to_s }.collect{ |s| unless ( /(\r|\n)\z/ =~ s ) s + $/ else s end }.join("") end |
#write(object) ⇒ Object
writes object to output stream
5 6 7 |
# File 'lib/web/stringio.rb', line 5 def write object self << object end |