Created
June 27, 2016 08:24
-
-
Save anonymous/e1ba58da452220fa7411a49f5d3233e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create new file and write text to it | |
io = IO.new(IO.sysopen("textfile.txt", "w+")) | |
io.write("first line\nsecond line\nthird line\n") | |
# check that write worked | |
io.rewind | |
puts io.sysread(4096) | |
io.rewind | |
# test String#prepend and IO#getbyte | |
tempstr = "" | |
io.each_char { | |
b = io.getbyte | |
if (b != nil) | |
tempstr.prepend([b].pack("C*")) | |
end | |
} | |
puts tempstr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment