array string ruby
- Create an array with strings in Ruby:
array = ["apple", "banana", "cherry", "date"]
- Access an element in the array:
puts array[1]
- Add an element to the end of the array:
array << "fig"
- Remove the last element from the array:
array.pop
- Iterate over the array using each:
array.each do |fruit|
puts fruit
end