LoginSignup
6
0

More than 3 years have passed since last update.

第6回

Last updated at Posted at 2020-12-03

variable 

お題

受け取った引数ARGV[0]をnameという変数(variable)に代入してそれを打ち出すcodeを書け.

> ruby name_variable.rb
Ruby

Rubyでの変数

rubyの変数は型宣言の必要性がなく,文脈に合わせて適当に型が定められます.イコールで代入されます.

name = 'Rudy'

method

お題

> ruby hello_method.rb Rudy
Hell Rudy.

と返すhello methodを作りなさい.

解説

Rubyではfunctionやprocedureなどのまとまりはmethodを定義(definition)することになります.methodは0個以上の引数(argument)を取ることができます.

def hello name
  puts "Hello #{name}."
end

name =ARGV[0]
hello(name)

  • source ~/grad_members_20f/members/Kazufumi0823/a3.org
6
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
6
0