General Flashcards

Based on information from http://www.zenspider.com/Languages/Ruby/QuickRef.html

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

What is a comment in Ruby code?

A

from # to end of line

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

A Ruby program is a sequence of…

A

expressions

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

How do you terminate an expression?

A

with a ; or end-of-line

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

Can an expression go beyond end-of-line?

A

Yes; if it is parsed as incomplete, parsing continues on next line

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

Is there a way to force an expression to run past end-of-line unconditionally?

A

Yes, by ending the line with a backslash \

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

What are the basic Ruby data types?

A

numbers, strings, ranges, regexes, symbols, arrays, hashes (and files?)

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

Can a large integer be broken up for readability?

A

Yes, with underscores, e.g. 1_000_000

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

How is a literal hexadecimal value denoted?

A

With “0x”, C style, e.g. 0xffff

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

How is a floating-point value expressed

A

C style, e.g. 1.2e-3

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

How is a literal octal value expressed

A

With “0” prefix, C style, e.g. 0377

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

How is a literal binary value expressed?

A

With “0b”, e.g. 0b01011

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

How is the literal value of an ASCII character expressed?

A

With a “?” prefix and no quotes, e.g. ?a

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

How is the literal value of an ASCII control character expressed?

A

Prefixed with “?\C-“, e.g. ?\C-a

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

How is the literal value of a “meta” character expressed?

A

Prefixed with “?\M-“, e.g. ?\M-a

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

What is the simplest way to express strings (non-interpolated, no escaping)?

A

Single quoted, e.g. ‘string’

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

What is the simplest way to express an interpolated string?

A

Double quoted, e.g. “value of #{variable}”

17
Q

Can an interpolated string use C-style backslash characters?

A

Yes (e.g. “\n” will be a newline)

18
Q

Can a non-interpolated string use C-style backslash characters?

A

No (e.g. ‘\n’ will literally be backslash + n)

19
Q

How else can a non-interpolated string be quoted?

A

%q(string)

20
Q

How can an interpolated string be quoted without quote marks?

A

%Q(string) or %(string)

21
Q

What is the simplest way to make a string a command to be executed in the shell?

A

Quoted with backticks, e.g. cat /etc/passwd

22
Q

How else can a shell-command string be quoted

A

%x(echo Hello)

23
Q

Can %-style strings be quoted any other way besides parentheses?

A

Yes, with matching pairs e.g. %q[string], %Q{string}, %x<echo string>; or any single char twice, e.g. %@string@, %Q!string!, %x,echo string,