Ruby Programming Language Flashcards

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

Leave a Comment ({[ getComments().length ]})

Comments ({[ getComments().length ]})

{[comment.username]}

{[ comment.comment ]}

View All {[ getComments().length ]} Comments
Ask a homework question - tutors are online