Ruby でも同じ -x オプションがあるとのことなので是非試してみたいですね!!
ほー面白い!ってことで、 Ruby でもやってみた
package main import ( "fmt" "io/ioutil" ) const script = ` #!ruby puts 'Hello, Ruby World!!' __END__ ` func init() { ioutil.Discard.Write([]byte(script)) } func main() { fmt.Println("This is Go World!!") }
$ go build -o main main.go $ ruby -x ./main Hello, Ruby World!!
ほぼ同じコードでちゃんと出力されたー!
-x[directory] strip off text before #!ruby line and perhaps cd to directory
Ruby の -x オプションも Perl とほぼ同じ機能。 Ruby は Perl インスパイアだからなるほどだ。
これを思いついて実行してみたのすごいなぁ。