Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2016 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e1ba58da452220fa7411a49f5d3233e3 to your computer and use it in GitHub Desktop.
Save anonymous/e1ba58da452220fa7411a49f5d3233e3 to your computer and use it in GitHub Desktop.
# 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