require 'optparse' require 'dimsum' include Dimsum options = {} OptionParser.new do |opts| opts.banner = "Usage: sample.rb [options]" opts.on("-n [Fixnum]", "--number [Fixnum]", "") do |n| options[:lines] = n end end.parse! options[:lines] ||= "5" lines = options[:lines].to_i reservoir_sample = if ARGV.length > 0 filename = ARGV[0] reservoir_file(filename, lines) else reservoir_stdin(lines) end reservoir_sample.each{ |l| STDOUT.print l }