1
0

More than 3 years have passed since last update.

Ruby: メソッド間での引数の受け渡し

Posted at

Ruby: メソッド間での引数の受け渡し。
忘れないようにメモ。
メソッドは呼び出されるまで動かない受け身な子。

def register_data(data)
puts '名前を入力してください'
name = gets.chomp
puts '年齢を入力してください'
age = gets.chomp
puts '身長を入力してください(m単位)'
tall = gets.to_f
puts '体重を入力してください'
weight = gets.to_f
person = { name: name, age: age, tall: tall, weight: weight, bmi: calculate_bmi(tall, weight)}
data << person
end

def calculate_bmi(tall, weight)
bmi = weight / tall / tall
end

1
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
1
0