Shared Flashcard Set

Details

Ruby Programming Language
Basic Ruby programming language questions
62
Computer Science
Undergraduate 4
07/03/2010

Additional Computer Science Flashcards

 


 

Cards

Term
What two categories of numbers does Ruby work with?
Definition
Integers and Floating Point
Term
How do you raise 2 to the second power?
Definition
2**2
Term
what are the two subclasses for integers?
Definition
Fixnum and Bignum
Term
How do you determine what type of number you are using?
Definition
the number with .class at the end
Term
What method rounds a floating point?
Definition
.round
Term
What method converts a float to an integer?
Definition
.to_i
Term
What method rounds down?
Definition
.floor
Term
What method will force a float to be rounded up?
Definition
.ceil
Term
How do you make the same string appear multiple times?
Definition
string * #
Term
What are advantages of using double quoted strings?
Definition
they evaluate backslashes so you can use both variables and special characters such as \t.
Term
What method displays the characters of a string in reverse?
Definition
.reverse
Term
What method capitalizes a string?
Definition
.capitalize
Term
What method presents a string in all lower case letters?
Definition
.downcase
Term
What method displays all characters in a string in upper case letters?
Definition
.upcase
Term
What method tells you how many characters are in a string?
Definition
.length
Term
What is the append operator that is used to add an element to the end of an array?
Definition
<<
Term
How do you substitute a null value to the first index of an array called data_set?
Definition
data_set[0] << nil
Term
What method returns the contents of an array and its structure?
Definition
.inspect
Term
What method puts all of the elements of an array into a string?
Definition
array.to_s
Term
How would you return the contents of an array as characters separated by a comma?
Definition
array.join(", ")
Term
How would you take the string x = "b,4,5,a,8" and make it an array called y that would have this structure: ["b", "4", "5", "a", "8"] ?
Definition
y = x.split(',')
Term
What method reverses the order of an element?
Definition
.reverse
Term
What method will sort an array of numbers?
Definition
.sort
Term
What method will return an array of only unique values?
Definition
.uniq
Term
What method will delete the element at the second position in an array?
Definition
delete_at(2)
Term
How do you delete a certain value in an array?
Definition
.delete(value)
Term
What is another way to add an element to an array other than <
Definition
.push()
Term
What method will remove the last element of an array for you?
Definition
.pop
Term
What method will remove the first element from an array?
Definition
.shift
Term
How would you undo a .shift method performed on an array?
Definition
.unshift
Term
How do you enclose a hash?
Definition
{}
Term
How do you point a key to a value in a hash?
Definition
=>
Term
What method do you use to find a key for a value?
Definition
.index("value")
Term
What method will display all the keys of a hash?
Definition
.keys
Term
What method will display all the values of a hash?
Definition
.values
Term
What method will show you how many values are in a hash?
Definition
.length
Term
What method will remove all the contents of a hash?
Definition
.clear
Term
What method will convert all the key value pairs into arrays?
Definition
.to_a
Term
What is the equals operator?
Definition
==
Term
What class is true?
Definition
TrueClass
Term
How do you determine if 2 is in between the values 1 and 4 using the .between method?
Definition
2.between?(1,4)
Term
What method would you use to determine of a key with the value of a is in a hash?
Definition
tested_key.has_key?('a')
Term
How would you display the contents of a range of numbers 1- 10 inclusive?
Definition
1..10
Term
How do you show the first number in a range?
Definition
.begin
Term
How do you show the last number of either an exclusive or inclusive range?
Definition
.end
Term
How do you determine if a range includes the number 5?
Definition
range_of_numbers.inlude?(5)
Term
How do you return the values of a range "x" as an array to z?
Definition
z = [*x]
Term
What command terminates a whole loop?
Definition
break
Term
What command moves processing to the next loop?
Definition
next
Term
What command causes the loop to redo itself?
Definition
redo
Term
What command starts the whole loop over?
Definition
retry
Term
how do you begin a do loop?
Definition
loop do
Term
How would you iterate 1 through five and print "Hello" to the screen?
Definition
1.upto(5){puts "Hello"}
Term
How would you iterate counting down to 1 and print "Hello" to the screen?
Definition
5.downto(1){puts "Hello"}
Term
How would you iterate through a range of 1 to 5 and print "Hello" to the screen each time?
Definition
(1..5).each{puts "Hello"}
Term
How do you end an if...else statement?
Definition
end
Term
How do you use the ternary operator to determine if "x" is equal to one and return yes if it is and no if it isn't?
Definition
puts x == 1 ? "yes" : "no"
Term
What is the syntax for a global variable?
Definition
$variable
Term
What is the syntax for a class variable?
Definition
@@variable
Term
What is the syntax for an instance variable?
Definition
@variable
Term
What is the syntax for a local variable?
Definition
variable
Term
What is the syntax for a block variable?
Definition
variable
Supporting users have an ad free experience!