Ruby Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

convert string to integer

A

.to_i

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

convert number to string

A

.to_s

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

convert to floating point number

A

.to_f

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

add an item to the end of an array

A

array.push

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

remove the last item in an array

A

array.pop

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

read (but don’t change) the last item in an array

A

array.last

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

syntax to access value of key in hash

A

hash_name[:key]

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

alternate syntax to access value of key in hash

A

hash_name.key

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

define CRUD

A

Create
Read
Update
Delete

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

How do you tell html.erb code to run ruby code?

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

How do you tell html.erb to show the result of the ruby code in the html?

A

by adding an = symbol

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

7 R on R controller actions

A
  1. Index
  2. Show
  3. New
  4. Edit
  5. Create
  6. Update
  7. Destroy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

method to form a string from the items in an array

A

my_array.join(“ “) # this would add a space between items in the string.

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

what is a range

A

a range of numbers or letters with two dots between then:

1..30 # numbers between 1 and 30

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

when you call a .each method on a hash and feed it a block, how many variables do you work with?

A

Two.
You are working with both the key and the key’s value. You don’t have to use them both, though. For example:
my_hash.each { |key, value| value = value + 1 }

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

what does the .inspect method do?

A

returns a string with the literal value of the object it’s called on

17
Q

Way to return the text plural of an array of objects

A

pluralize(1, “dog”) => “1 dog”

pluralize(2, “dog”) => “2 dogs”