Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby file open append

# Write file
File.open("log.txt", "w") { |f| f.write "#{Time.now} - User logged in
" }
# or
File.write("log.txt", "data...")

# Append file
File.open("foo.txt", "a") { |f| f.write "#{Time.now} - User logged in
" }
# or
File.write("log.txt", "data...", mode: "a")

# Other Variants
File.open("out.txt", [your-option-string]) {|f| f.write("write your stuff here") }

# where your options are:
#   r - Read only. The file must exist.
#   w - Create an empty file for writing.
#   a - Append to a file.The file is created if it does not exist.
#   r+ - Open a file for update both reading and writing. The file must exist.
#   w+ - Create an empty file for both reading and writing.
#   a+ - Open a file for reading and appending. The file is created if it does not exist.
Comment

ruby open file and append

File.open("foo.txt", "a") { |f| f << "foo" }
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails devise valid_password 
Ruby :: rails change resource name 
Ruby :: What does inject in ruby do 
Ruby :: command to install ruby gems 
Ruby :: arel_table rails 
Ruby :: input must be integer in ruby 
Ruby :: dynamic database connection in rails 
Ruby :: rails retrieve database.yml 
Ruby :: select tag . Default value rails 
Ruby :: ruby deep copy 
Ruby :: ruby constructors 
Ruby :: ruby array loop 
Ruby :: ide for ruby 
Ruby :: how to add variable inside string ruby 
Ruby :: string formattion ruby 
Ruby :: ruby named parameters 
Ruby :: rails interrupt if tooo long 
Ruby :: using nested select in rails query 
Ruby :: self join relationship rails 
Ruby :: rails ago 
Ruby :: logstash-logger gem 
Ruby :: ruby &w 
R :: linetype ggplot in r 
R :: WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding: 
R :: extract r squared from lm in r 
R :: create dataframe or table in r 
R :: convert datetime from string r 
R :: How to calculate regression line in R 
R :: R darekn color 
R :: r prepend to a list 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =