Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created October 16, 2012 18:36
Show Gist options
  • Save myronmarston/3901132 to your computer and use it in GitHub Desktop.
Save myronmarston/3901132 to your computer and use it in GitHub Desktop.
➜ irb
1.9.3p194 :001 > string = "This is a string"
=> "This is a string"
1.9.3p194 :003 > require 'stringio'
=> true
1.9.3p194 :004 > io = StringIO.new(string)
=> #<StringIO:0x007f988402a890>
1.9.3p194 :005 > io.read(2)
=> "Th"
1.9.3p194 :006 > string.slice!(2, -1)
=> nil
1.9.3p194 :007 > io.read(2)
=> "is"
1.9.3p194 :008 > string.slice!(2, -1)
=> nil
1.9.3p194 :009 > io.read
=> " is a string"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment