Ruby Methods Flashcards
puts
kernel method that outputs a statement to the screen as a string
to_s
converts to string
to_i
converts to integer
to_f
converts to float
gets
a kernel method to retrieve strings
chomp
removes the carriage return from user inputs
reverse
reverses a string
length
gives the total amount if characters in a string, including spaces. the result is an integer.
also gives the number of objects in an array.
upcase
changes all letters to uppercase
downcase
changes all letters to lowercase
swapcase
switches the cases on letters
capitalize
changes the first character in a string to uppercase if it is a letter
center
centers a string on a line. argument = total line width to center the string in.
ljust
left justifies a string on a line. argument = total line width to center the string in.
rjust
right justifies a string on a line. argument = total line width to right justify the string in.
**2
squared
**.5
square root
%
modulus. gives the remainder of a number
abs
absolute of a number
rand
generates random numbers.
if argument is blank, rand uses 0.0-1.0 floating point
rand generates numbers minus 1 of the argument
argument of 1 = 0
srand
the seed for rand.
argument must be a number.
memorizes a sequence for random numbers.
what are the comparison methods?
> greater than this < lesser than this >= greater or equals to <= lesser or equals to == equals to != not equal to
how does ruby compare strings with comparison methods?
alphabetically by the dictionary (lexicographically) < comes before: ie 'cat' < 'dog' = true > comes after: ie 'dog' > 'cat' = true
however, capital letters come before lowercase
ie ‘cat’ < ‘Dog’ = false
same goes for numbers
ie 2 < 10: true but,
‘2’ < ‘10’: false
each
an array iterator that lets you perform something to each slot of an array
times
a number iterator that repeats an action equivalent to the number
push
array method that adds an object to the end of an array
pop
array method that removes the last object of an array
last
an array method that uses the last entry of an array
join
array method that joins objects together. The argument used is a delimiter ie comma.