Intro to Ruby Book Flashcards

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

variables

A

used to store information to be referenced and manipulated in a computer program, provide a way of labeling data with a descriptive name

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

like containers that hold info

A

variables

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

.chomp

A

used after any string to remove the extra characters at the end

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

method

A

(early defintion) pieces of reusable code that a program can execute many times

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

How is a block delimited?

A

IT is delimited by either { }, or do/end

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

Ruby methods ALWAYS return the evaluated result of the last line of the expression unless an explicit xxxx comes before it.

A

RETURN

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

Method analogy

A

Like a hammer in your backback

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

Does the pop method mutate the caller?

A

Yes, the original array variable is modified

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

How do you add an item back to an array permanently?

A

array.push
OR («)

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

The _____ method iterates over an array applying a block to each element of the array and returns a new array with those results.

A

map or collect method

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

Is a map/collect method destructive? (Does it mutate the caller)

A

No it does not mutate the caller

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

Object ID

A

Every Object has a unique object ID

x.object_id

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

How do you get two of the same object ID?

A

if 2 immutable objects have the same value they have the same object ID

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

The calling object

A

The object that the method is invoked upon

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

What can be passed to methods as arguments

A

Only objects (not variables)

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

Usually ____ have a “meaningful” return value that is meant to be “used” in some way

A

non-mutating methods

17
Q

Map vs. Each

A

If you want to change your return value: use map. If you want to use the same return value that you started with use .each. (Each is more flexible).

18
Q

What is the return value of .each?

A

The same value as the original array

19
Q

What will the input be?
def speak(words)
puts words
end

speak(“There are around 700 separate programming languages”)

A

You can pass in a string as an argument without putting it in a local valuable first.

output: There are around 700 separate programming languages

20
Q

year = 1986

def virus(year)
puts “The first computer virus was created in #{year}
end

virus

A

ERROR

21
Q

default paramaters

A

you can invoke the method without passing an argument

22
Q

Arguments are used in….

A

method invocations

23
Q

Parameters are used in…

A

method definitions