rubyhardway Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

.rb file

A

file that contains ruby formatted code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

-- coding: utf-8 --

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

formatter = “%{first} %{second} %{third} %{fourth}”

puts formatter % {first: 1, second: 2, third: 3, fourth: 4}

A

1 2 3 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

\

A

backslash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

'

A

single quote

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

"

A

double-quote

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

escape characters

A

escape from the literal meaning of a character in your code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

\n

A

new line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

\b

A

backspace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

\t

A

tab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

gets vs gets.chomp

A

gets takes user input with a \n at the end, chomp removes the \n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ARGV

A

argument variable. holds the arguments you pass to your ruby script when you run it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

puts “Where do you live #{user_name}? “, prompt ||explain prompt

A

variable prompt that is set to the prompt we want.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

read from a file in ruby

A

txt = open(file_name)

txt. read
txt. close

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

target = open(filename, ‘w’)

what is ‘w’

A

‘w’ means write-only, truncates existing file to zero length or create a new file for writing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

f.seek(0)

A

seek deals with bytes, so its going to the first byte in the file