Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Created July 31, 2012 17:25
Show Gist options
  • Select an option

  • Save tarcieri/3218710 to your computer and use it in GitHub Desktop.

Select an option

Save tarcieri/3218710 to your computer and use it in GitHub Desktop.
For people with crazysauce ideas about the interactions of Ruby IO objects and #each
1.9.3-p0 :001 > reader, writer = IO.pipe
=> [#<IO:fd 5>, #<IO:fd 6>]
1.9.3-p0 :002 > writer.respond_to? :each
=> true
1.9.3-p0 :003 > reader.respond_to? :each
=> true
1.9.3-p0 :004 > class << reader; undef :each; end
=> nil
1.9.3-p0 :005 > class << writer; undef :each; end
=> nil
1.9.3-p0 :006 > reader.respond_to? :each
=> false
1.9.3-p0 :007 > writer.respond_to? :each
=> false
1.9.3-p0 :008 > writer << "data"
=> #<IO:fd 6>
1.9.3-p0 :009 > reader.read(4)
=> "data"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment