Method: URI#download
- Defined in:
- lib/fe_core_ext/core_ext/uri.rb
#download(file) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/fe_core_ext/core_ext/uri.rb', line 9 def download(file) warn "URI#downloadの引数にはPathnameを使いましょう!" if file.is_a?(String) binary = OpenURI.open_uri(self).read file = file + self.basename if file.to_s[-1] == "/" dirname = ::File.dirname(file) ::FileUtils.mkdir_p(dirname) unless ::File.directory?(dirname) ::File.open(file, "wb") { |f| f.write(binary) } end |