Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Kernel | `command`

概要

Kernel#`command`

詳細

command を外部コマンドとして実行し、その標準出力を文字列として 返します。
このメソッドは `command` の形式で呼ばれます。

Kernel.#systemはcommandの結果を得ることができないのが違いです。

サンプルコード
# encoding: utf-8
require 'tbpgr_utils'

puts "Kernel#`` => #{`rspec -v`}"
puts $?
puts "Kernel#system => #{system('rspec -v')}"
出力
2.14.8
Kernel#`` => 2.14.8
pid 3316 exit 0
Kernel#system => true