Last active
June 22, 2016 09:25
-
-
Save ksss/1123c4981774e530a8f577cb10ec1e9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
class MultiDownload | |
def initialize(*urls) | |
@urls = urls | |
end | |
def to_h | |
@urls.map { |url| | |
Thread.new(url) do |url| | |
content = open(url, &:read) rescue nil | |
[url, content] | |
end | |
}.map(&:value).to_h | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment