Ruby Flashcards
convert string to integer
.to_i
convert number to string
.to_s
convert to floating point number
.to_f
add an item to the end of an array
array.push
remove the last item in an array
array.pop
read (but don’t change) the last item in an array
array.last
syntax to access value of key in hash
hash_name[:key]
alternate syntax to access value of key in hash
hash_name.key
define CRUD
Create
Read
Update
Delete
How do you tell html.erb code to run ruby code?
How do you tell html.erb to show the result of the ruby code in the html?
by adding an = symbol
7 R on R controller actions
- Index
- Show
- New
- Edit
- Create
- Update
- Destroy
method to form a string from the items in an array
my_array.join(“ “) # this would add a space between items in the string.
what is a range
a range of numbers or letters with two dots between then:
1..30 # numbers between 1 and 30
when you call a .each method on a hash and feed it a block, how many variables do you work with?
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 }