7
8

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 5 years have passed since last update.

eachメソッド

Posted at

配列・ハッシュに対して先頭のデータから順に繰り返し全ての処理を行うためのメソッド

配列.each do |変数|
繰り返した処理     
end          

ハッシュ.each do |キー変数, 値変数|
繰り返した処理
end          

   data = ["東京", "大阪", "京都"]
   
   data.each do |value|
     puts value
   end  

   colors = {"apple" => "赤色", "banana" => "黄色"}

   colors.each do |key, value|
    puts "#{key}:#{value}"
    puts "#{value}は#{key}が美味しい証拠です。"
   end  
7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?