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

ruby 演習メモ I (puts)

Last updated at Posted at 2020-12-31

目的

ruby のコードを実際に書いてみよう.
今回は第 I 弾.

お題 その1

ruby で hello_world.
(https://qiita.com/daddygongon/items/1b0f0ff3fb9d60418289 にある課題)

今回書いた code


# require
require 'pp'

# start here output
puts	'hello world'

p	'hello world'

pp	'hello world'

print	'hello world'

printf	'hello world'

解説

code に対する解説は特にない. あんな感じに書けば出力される.
各種 method の解説については先程載せたリンク先にあるからそこを見よう.

お題 その2

受け取った文字列に対して hello.
(先程のリンク先にある課題)

今回書いた code


puts	"Hello #{ARGV[0]}."

#puts	"Hello " + ARGV[0] + "."

#print	"Hello #{ARGV[0]}.\n"

#print	"Hello " + ARGV[0] + ".\n"

#printf("Hello %s.\n", ARGV[0])

解説

さっきの code をちょっと書き換えるだけで良い. (ARGV[0] を使えばいい)
そうすると,

> ruby hello_name.rb sonic
Hello sonic.

こうなる

参考資料

チャート式ruby-I(puts)


  • source ~/Lecture/multiscale_simulation/grad_members_20f/members/gagagagazelle/docs/c1_puts.org
2
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
2
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?