Ruby - Call system command in double-quoted strings

Introduction

You can also embed commands inside double-quoted strings like this:

Demo

print( "Goodbye #{%x{dir main.rb}}" ) 

print( "Goodbye #{%x{ruby}}" )

Result

The command itself is evaluated first.

Your Ruby program then waits until the process that starts has terminated.

Related Topic