「Ruby入門」変数を文字列に含めるサンプル
書式
#{式}
使用例
#!/usr/bin/ruby # -*- coding: UTF-8 -*- m= 10 n= 20 res1= m +n puts "result1 value is #{res1}" res2= m - n puts "result2 value is #{res2}" res3= m * n puts "result3 value is #{res3}" res4= m % n puts "result4 value is #{res4}"
実行結果
>ruby test.rb
result1 value is 30
result2 value is -10
result3 value is 200
result4 value is 10