6
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.

第5回

Last updated at Posted at 2020-12-04

出力メソッド

rubyでStringsを打ち出すのにはいくつかの方法があり,どれを使ってもいい.

method 使用状況
print 普通に使う.要改行
puts 次に普通に使う. 自動改行
p codingの最中にdebugがわりに打ち出すとき
pp pのpretty print, require 'pp'が必要
printf cのがあります.formatを整えるときに便利

簡単な解説

putsしたら普通はgetsなんですが,目的の一つであるshell環境ではcommand line interfaceで作業をするためにARGV[0]というのを使って行きます.

ARGV[0]というのは引数(argument)配列の0番目を意味しています.

"Hello Rudy."と打ち出させることをかんがえます.これをするにはいくつかの方法があります.

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

  • source ~/grad_members_20f/members/Kazufumi0823/a2.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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?