如何用ruby调用另一个ruby脚本?

Python035

如何用ruby调用另一个ruby脚本?,第1张

system(“.ruby”)或者load 'another.rb'

具体代码如下:

# 返回ls的输出

s=`ls`

cmd= "ls"

s= `#{cmd}`

# 返回true or false

s= system('ls')

cmd= 'ls'

s= system(cmd)

#返回输出

s= %x[uptime]

#用top进程替换当前ruby进程

exec "top"

cmd = 'top'

exec cmd

may be you can paste this to your ~/.bashrc file ,

alias exemyfile="ruby myrubyfile.rb"

then enter exemyfile command in your terminal, it works as you want.