rubyhardway Flashcards
.rb file
file that contains ruby formatted code
-- coding: utf-8 --
Ruby still ignores that as code, but it’s used as a kind of “hack” or workaround for problems with setting and detecting the format of a file.
formatter = “%{first} %{second} %{third} %{fourth}”
puts formatter % {first: 1, second: 2, third: 3, fourth: 4}
1 2 3 4
\
backslash
'
single quote
"
double-quote
escape characters
escape from the literal meaning of a character in your code
\n
new line
\b
backspace
\t
tab
gets vs gets.chomp
gets takes user input with a \n at the end, chomp removes the \n
ARGV
argument variable. holds the arguments you pass to your ruby script when you run it.
puts “Where do you live #{user_name}? “, prompt ||explain prompt
variable prompt that is set to the prompt we want.
read from a file in ruby
txt = open(file_name)
txt. read
txt. close
target = open(filename, ‘w’)
what is ‘w’
‘w’ means write-only, truncates existing file to zero length or create a new file for writing.