Intro to Ruby Book Flashcards
variables
used to store information to be referenced and manipulated in a computer program, provide a way of labeling data with a descriptive name
like containers that hold info
variables
.chomp
used after any string to remove the extra characters at the end
method
(early defintion) pieces of reusable code that a program can execute many times
How is a block delimited?
IT is delimited by either { }, or do/end
Ruby methods ALWAYS return the evaluated result of the last line of the expression unless an explicit xxxx comes before it.
RETURN
Method analogy
Like a hammer in your backback
Does the pop method mutate the caller?
Yes, the original array variable is modified
How do you add an item back to an array permanently?
array.push
OR («)
The _____ method iterates over an array applying a block to each element of the array and returns a new array with those results.
map or collect method
Is a map/collect method destructive? (Does it mutate the caller)
No it does not mutate the caller
Object ID
Every Object has a unique object ID
x.object_id
How do you get two of the same object ID?
if 2 immutable objects have the same value they have the same object ID
The calling object
The object that the method is invoked upon
What can be passed to methods as arguments
Only objects (not variables)