Skip to content

Instantly share code, notes, and snippets.

@akkunchoi
Created February 2, 2012 15:29
Show Gist options
  • Save akkunchoi/1723998 to your computer and use it in GitHub Desktop.
Save akkunchoi/1723998 to your computer and use it in GitHub Desktop.
download file
require 'open-uri'
def download_as_file(url)
filename = File.basename(url)
open(filename, 'wb') do |file|
open(url) do |data|
file.write(data.read)
end
end
end
url = 'http://d.hatena.ne.jp/images/diary/g/gan2/gan2_p.gif'
download_as_file(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment