LoginSignup
1
1

More than 3 years have passed since last update.

Ruby 配列 に 格納 された ものを 順に出力する

Posted at

目的

  • Rubyにて、配列に格納された文字列などを順に出力する方法を知る。

書き方の例

  • 変数_1には配列の形で任意の文字列が2つ以上格納されていることとする。
  • 下記にRubyの処理を記載する。
変数_1.each do |変数_2|
  puts 変数_2
end

より具体的な例

  • 変数stringに「みりを」「miriwo」「MIRIWO」を配列として格納する。
  • 変数stringの中身を一つづつ出力為る。
  • 下記にRubyの処理を記載する。
# 変数への文字列格納
strings = ["みりを", "miriwo", "MIRIWO"]

# eachを用いてstringsの中身を一つづつstringに格納
string.each do |string|
# stringに格納された中身を出力
puts string
# eachを閉じる
end
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1