0
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 1 year has passed since last update.

Ruby % 使う方

Last updated at Posted at 2022-07-02

Ruby % 使う方

%q

シングルクオートで囲う場合と同等(どうとう)、シングルクオートなので、変数や定数の展開はされない

language = "ruby"
str = %q(Programming language is "#{language}")
puts str
# => Programming language "#{ruby}"

%Q

ダブルクオートで囲う場合と同等(どうとう) 変数や定数の展開はできます

language = "ruby"
str = %Q(Programming language is "#{language}")
puts str 

# => Programming language is ruby

%w

 配列を作る 、式の展開はされない

arr = %w(apple orange banana)
puts arr
# => ["apple","orange","banana"]

%W

PYTHON = 'python'
arr = %W(#{PYTHON} ruby)

%i

要素がsymbol配列を作る

array = %i(Ruby Python PHP)
p array
# => [:Ruby, :Python, :PHP]

%I

要素がsymbol配列を作る 式の展開はできます

ruby = "Ruby"
array = %I(#{ruby} Python PHP)
p array
# => [:Ruby, :Python, :PHP]

%s

symbol

res = %s(ruby)
put res
# => :ruby

%x

コマンド出力を行おう

puts %x(date)
# => 2022年 7月 2日 土曜日 17時40分31秒 CST
0
0
1

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