-
-
Save fairchild/21182 to your computer and use it in GitHub Desktop.
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
f = File.new("myfile.txt", "r") # open a file with read-mode | |
# ... do some stuff with the file, like read its content, ouput it on the screen or whatever | |
# finally: close it! | |
f.close | |
# or: | |
File.new("myfile.txt", "w") do |f| | |
# now here you can do stuff with f (the file) same as above | |
# only that you don't have to close the file manually, it gets done automatically once the block has ended. | |
# the code for closing is inside the constructor of file and gets executed | |
# a) if there is a block given => after the block has finished | |
# b) not at all, if no block is given (needs to be called manually) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment