[Ruby] Array

What is an array?

--Those that manage multiple pieces of information in order --One variable can have multiple values --Multiple values can be entered in the array

input

names = ["Tanaka","Yamada","Sato"]

puts names

output

Tanaka
Yamada
Sato

Add value (<<)

Add a value to the end of the array.

input

names << "Suzuki"

puts names

output

Tanaka
Yamada
Sato
Suzuki

Get array values

Specify and get the subscript. input

name = names[0]
puts name

name = names[2]
puts name

output

Tanaka
Sato

Change array values

input

puts name[1]
names[1] = "Sasaki"
puts name[1]

output

Yamada
Sasaki

Recommended Posts

[Ruby] Array
Ruby two-dimensional array
Ruby array manipulation
Array
Array
[Ruby] Extracting a two-dimensional array
Multiplication in a Ruby array
[Ruby] Get array elements alternately.
Sorting hashes in a Ruby array
Ruby learning 4
Java array
Array practice
Ruby basics
Ruby learning 5
Java array
Ruby basics
java (array)
Ruby Review 2
Ruby addition
Refactoring Ruby
Java array
[Java] Array
Ruby learning 3
[Ruby] Extracting double hash in array
Array practice 2
Ruby setting 2
Java array
Hanachan in Ruby (non-destructive array manipulation)
Ruby problem ⑦
Ruby learning 2
[Ruby] Block
Refactoring Ruby
ruby calculator
Ruby learning 6
12 of Array
Ruby settings 1
Refactoring Ruby
Explanation about Array object of Ruby
java array
[Java] Array
Ruby basics
What is a Ruby 2D array?
Ruby memo
Ruby learning 1
Ruby Review 1
[Ruby] Module
[Ruby] Get unique elements from an array
Sort an array of Ruby homebrew classes
Introduction to Ruby 2
Ruby input / output
ruby Uppercase letters
ruby search problem
Ruby Learning # 25 Comments
ruby constant variable
Ruby to_s method
[Ruby] postfix if
java array variable
[Ruby] Calculation by extracting elements from an array
[Ruby] FizzBuzz problem
Ruby text conversion
Ruby basic terms