Created
April 16, 2012 09:51
-
-
Save shime/2397386 to your computer and use it in GitHub Desktop.
writting string to file
This file contains 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
# downloading content from the web | |
require 'open-uri' | |
url = 'http://blog.stackoverflow.com/audio/stackoverflow-podcast-001.mp3' | |
open(url).read.to_file(url.split('/').last) | |
# And boom, you’ve downloaded the file to “stackoverflow-podcast-001.mp3” |
This file contains 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
class String | |
def to_file(filename) | |
File.open(filename, 'w') {|f| f.write self } | |
end | |
end | |
"Hello file!".to_file("hello.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment