Skip to content

Instantly share code, notes, and snippets.

@you-ssk
Created September 18, 2016 06:21
Show Gist options
  • Save you-ssk/c76e9b507d30bc83442fb18e7989beda to your computer and use it in GitHub Desktop.
Save you-ssk/c76e9b507d30bc83442fb18e7989beda to your computer and use it in GitHub Desktop.
def empty?(e)
e.peek
false
rescue
true
end
def merge(*src)
src = src.map{|s| s.to_enum}
while true
src = src.delete_if{|s| empty?(s)}
return if src.empty?
it = src.min_by {|e| e.peek.to_i}
yield(it.next.to_i)
end
end
if __FILE__ == $0
merge(File.open('aaa'), File.open('bbb')){|x| p x}
merge(File.open('aaa'), [2,5,11,12,13,90]){|x| p x}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment