Ruby Methods Flashcards

1
Q

puts

A

kernel method that outputs a statement to the screen as a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

to_s

A

converts to string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

to_i

A

converts to integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

to_f

A

converts to float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

gets

A

a kernel method to retrieve strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

chomp

A

removes the carriage return from user inputs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

reverse

A

reverses a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

length

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

upcase

A

changes all letters to uppercase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

downcase

A

changes all letters to lowercase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

swapcase

A

switches the cases on letters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

capitalize

A

changes the first character in a string to uppercase if it is a letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

center

A

centers a string on a line. argument = total line width to center the string in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

ljust

A

left justifies a string on a line. argument = total line width to center the string in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

rjust

A

right justifies a string on a line. argument = total line width to right justify the string in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

**2

A

squared

17
Q

**.5

A

square root

18
Q

%

A

modulus. gives the remainder of a number

19
Q

abs

A

absolute of a number

20
Q

rand

A

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

21
Q

srand

A

the seed for rand.
argument must be a number.
memorizes a sequence for random numbers.

22
Q

what are the comparison methods?

A
> greater than this
< lesser than this
>= greater or equals to
<= lesser or equals to
== equals to
!= not equal to
23
Q

how does ruby compare strings with comparison methods?

A
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

24
Q

each

A

an array iterator that lets you perform something to each slot of an array

25
Q

times

A

a number iterator that repeats an action equivalent to the number

26
Q

push

A

array method that adds an object to the end of an array

27
Q

pop

A

array method that removes the last object of an array

28
Q

last

A

an array method that uses the last entry of an array

29
Q

join

A

array method that joins objects together. The argument used is a delimiter ie comma.