Ruby Cheats

Ruby Cheats

Download File

this properly handle redirects

require 'open-uri'

url = ''
output_file = 'path/to/file', "w") do |f|
  IO.copy_stream(open(url), f)

Execute Process

There’s about 50 different ways to do this in ruby. Googling on this is quite disorienting. Below are the approaches that have all worked for me just fine. They are work the same as best I can tell.

puts %x( some command string )
def run(cmd)
  system(cmd) || raise "command '#{cmd}' failed"