0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rubyのeach文について

Posted at

はじめに

※以下の内容には誤りが含まれる可能性があります

each文とは何か

each文つまりeachメソッドは、配列またはハッシュの要素を1

つずつ取り出し、ブロック構文その要素を使った処理を記述できるメソッドです。

eachメソッドの文法

配列.each do |変数|
処理
end
array.rach do |element|
putus element
end
# eachメソッドの返り値
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

配列の要素を順に||内で取り出し、続く処理で変数を用いたプログラムを記述します。

まとめ

  • eachメソッドは、配列の要素を1つずつ取り出してくれるメソッド
  • 取り出した要素に対して処理をすることができる
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?