这个问题在这里已有答案:
是否有一个ruby函数来搜索(Linux)系统路径中的可执行文件?
我知道我可以这样做:
path = `which ls` # found if $?.exitstatus == 0
但它有一种红宝石的方式吗?就像是:
find_in_path('ls') # => '/bin/ls'
>> require 'mkmf'
=> true
>> find_executable 'ls'
checking for ls... yes
=> "/bin/ls"
>> find_executable 'no-such-command'
checking for no-such-command... no
=> nil