「Ruby入門」シフト演算子<<で文字列を結合するサンプル

2020年12月25日

書式
文字列A <<文字列B
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
strA = "Study "
strB = " Ruby in arkgame"
strC = " com"
# 文字列Aと文字列Bを結合
strA << strB
puts strA
# 文字列Aと文字列Bと文字列Cを結合
strA << strB << strC
puts strA
#!/usr/bin/ruby # -*- coding: UTF-8 -*- strA = "Study " strB = " Ruby in arkgame" strC = " com" # 文字列Aと文字列Bを結合 strA << strB puts strA # 文字列Aと文字列Bと文字列Cを結合 strA << strB << strC puts strA
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-

strA = "Study "
strB = " Ruby in arkgame"
strC = " com"

# 文字列Aと文字列Bを結合
strA << strB
puts strA

# 文字列Aと文字列Bと文字列Cを結合
strA << strB << strC
puts strA

実行結果
>ruby test.rb
Study Ruby in arkgame
Study Ruby in arkgame Ruby in arkgame com

Ruby

Posted by arkgame