Deck 6: Working With Collections of Data
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
Play
Full screen (f)
Deck 6: Working With Collections of Data
1
Every item stored within a hash is assigned both a key as well as a unique index position.
False
2
An array is an indexed collection of key-value pairs.
False
3
Unlike other types of Ruby objects, you cannot create a new array using the new method.
False
4
Like most other programming languages, Ruby requires that an array be declared in advance of its use.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
Unlike arrays, hashes are limited to storing only numeric and string data.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
The Array class's shift method can be used to delete the first item in an array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
An easy way to determine if a hash contains any key-value pairs is to execute the full? method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
The Array class's insert_at is the opposite of the delete_at method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
9
The Array class's last method can be used to retrieve the first or last item from an array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
The clear method can be used to remove all key-value entries from a hash.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
The reverse method can be used to generate a list of array items in the opposite order that they are actually stored.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
The Hash class's delete method can be used to remove a key-value pair based on a supplied key.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
Ruby requires that the size of an array be specified when the array is defined.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
Although the each loop can be used to process the content of an array, you are generally better off using a while or until loop.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
Values stored within an array are referenced based on their index position within the array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
An array's index begins at 0 and is incremented by one each time a new item it added.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
The push and pop methods are used to add new items to the end of an array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
18
The Array class's pop method is used to delete an item from the end of an array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
The slice method can be used to retrieve a range of value from an array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
As arrays grow in size it takes more and more time to process and retrieve array items.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
Ruby arrays start with an index position of ____?
A) 0
B) 1
C) 2
D) -1
A) 0
B) 1
C) 2
D) -1
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following methods can be used to retrieve the last array item?
A) midlle
B) at
C) last
D) first
A) midlle
B) at
C) last
D) first
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following methods can be used to retrieve a series of items from an array?
A) range
B) mode
C) slice
D) range?
A) range
B) mode
C) slice
D) range?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following methods can be used to determine if an array contains any items.
A) empty?
B) nothing?
C) full?
D) None of the above
A) empty?
B) nothing?
C) full?
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
The inspect method can be used to convert the contents of a hash into an array and vice versa.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
In addition to variables, Ruby also permits the storage of collections of data using which of the following constructs?
A) Arrays and Hashes
B) Lists and Collections
C) Variables and Constants
D) None of the above
A) Arrays and Hashes
B) Lists and Collections
C) Variables and Constants
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following methods can be used to retrieves the first element stored in an array?
A) first
B) @
C) in
D) None of the above
A) first
B) @
C) in
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
Ruby permits the specification of a negative integer value when referring to array values. An index value of -2 would refer to which item in an array?
A) The first item stored in the array
B) The second item stored in the array
C) The last item stored in the array
D) The second to last item stored in the array
A) The first item stored in the array
B) The second item stored in the array
C) The last item stored in the array
D) The second to last item stored in the array
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following methods can be used to retrieve an array item based on its index position?
A) @
B) at
C) #
D) in
A) @
B) at
C) #
D) in
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following methods allows you to delete an array item based on its value?
A) value
B) remove
C) delete
D) None of the above
A) value
B) remove
C) delete
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements is not valid?
A) cars = Array.new
B) cars = %w(Pinto Corvette Viper)
C) cars = ["Pinto", "Corvette", "Viper"]
D) None of the above
A) cars = Array.new
B) cars = %w(Pinto Corvette Viper)
C) cars = ["Pinto", "Corvette", "Viper"]
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following methods automatically iterates once for each item stored in an array?
A) each
B) while
C) until
D) next
A) each
B) while
C) until
D) next
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following options can be used to determine if an array contains any values?
A) Use the Array class's size method
B) Use the Array class's empty? method
C) Use the Array class's length method
D) All of the above
A) Use the Array class's size method
B) Use the Array class's empty? method
C) Use the Array class's length method
D) All of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
The following statement is an example of chaining methods together. fruit.sort.reverse.inspect
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following methods can be used to remove all of the items from an array?
A) empty
B) remove
C) delete
D) clear
A) empty
B) remove
C) delete
D) clear
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
You can use the Hash class's hash method to generate a list of all of the keys stored in a hash.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
As a hash grows in size it takes more and more time to process and retrieve hash key-item pairs.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
Taking the output of one method and using it as input for a subsequent method is accomplished through a process referred to as ____ the two methods together.
A) appending
B) chaining
C) binding
D) linking
A) appending
B) chaining
C) binding
D) linking
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
Ruby permits the use of both real number and integers as index position values.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following loops can be used to process the contents of an array?
A) while
B) each
C) until
D) All of the above
A) while
B) each
C) until
D) All of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following methods can be used to generate a list of hash keys?
A) list
B) keys
C) hash
D) All of the above
A) list
B) keys
C) hash
D) All of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
In contrast to an array, the time it takes to retrieve data from a hash ____ as the hash grows in size.
A) is greater
B) is less
C) is about the same
D) varies back on the type of data stored
A) is greater
B) is less
C) is about the same
D) varies back on the type of data stored
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
What is a collection of key-value pairs called?
A) Associative Array
B) Dictionary
C) Hash
D) All of the above
A) Associative Array
B) Dictionary
C) Hash
D) All of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
What happens if you accidentally assign a new value to a hash using a key that already exists?
A) The new value replaces the previous values
B) The original value is retained and the new value is disregarded
C) An error occurs and your script stops executing
D) None of the above
A) The new value replaces the previous values
B) The original value is retained and the new value is disregarded
C) An error occurs and your script stops executing
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following methods can be used to conditionally delete key-value pairs from a hash?
A) delete
B) delete_at
C) delete_if
D) remove
A) delete
B) delete_at
C) delete_if
D) remove
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
46
One way of creating a new hash is to take the contents of two existing hashes and combine them together using the _______________ method.
A) combine
B) append
C) merge
D) None of the above
A) combine
B) append
C) merge
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck