Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Instantly share code, notes, and snippets.

@udzura
Created December 13, 2012 05:47
Show Gist options
  • Save udzura/4274342 to your computer and use it in GitHub Desktop.
Save udzura/4274342 to your computer and use it in GitHub Desktop.
IO#each_segment
class IO
def each_segment(n)
if block_given?
while segment = read(n)
yield segment
end
else
enum_for(:each_segment, n)
end
end
end
##
# Usage
# I want you lazy!!!
File.open('/dev/urandom').each_segment(64).lazy.map{|v| [v].pack('m') }.first 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment