The easiest way if the file isn’t too long is:
puts File.read(file_name)
Indeed, IO.read
or File.read
automatically close the file, so there is no need to use File.open
with a block.
More Related Contents:
- How to search file text for a pattern and replace it with a given value
- How to write to file in Ruby?
- What are the Ruby File.open modes and options?
- How to search a folder and all of its subfolders for files of a certain type
- Reading the last n lines of a file in Ruby?
- Read binary file as string in Ruby
- Compute percentage of cents total
- What does map(&:name) mean in Ruby?
- What does ||= (or-equals) mean in Ruby?
- What does !! mean in ruby?
- Is there an efficient way to perform hundreds of text substitutions in Ruby?
- ‘pass parameter by reference’ in Ruby?
- Methods in Ruby: objects or not?
- How to Uninstall RVM? [duplicate]
- sqlite3-ruby install error on Ubuntu
- Need a simple explanation of the inject method
- Backslashes in single quoted strings vs. double quoted strings
- Is there any wisdom behind “and”, “or” operators in Ruby?
- DRY Ruby Initialization with Hash Argument
- Exporting an Environment Variable in Ruby
- ruby inheritance vs mixins
- Understanding the “||” OR operator in If conditionals in Ruby
- In Ruby, how does coerce() actually work?
- How to check if a Ruby object is a Boolean
- Is there a way to remove the BOM from a UTF-8 encoded file?
- How to run untrusted Ruby code inside a safe sandbox?
- Invalid function in ruby
- How to preserve request url with nginx proxy_pass
- Method and variable name is the same
- Combine two Arrays into Hash