我試圖理解呈現在this site腳本:Ruby中的百分號+管道運算符的含義如「%|」中的含義?
#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb'
def terminal_script_filepath
%|tell application "Terminal"
activate
do script "jsc -i #{e_as(e_sh(ENV['TM_FILEPATH']))}"
end tell|
end
open("|osascript", "w") { |io| io << terminal_script_filepath }
最重要的是,部分在功能terminal_script_filepath
開頭:
%| …
… |
...以及它在「分析」:
{ |io| io << terminal_script_filepath }
這裏使用了哪些Ruby的概念?
我知道open()
與管道幫我喂輸入到程序的標準輸入,但如何輸入從terminal_script_filepath
到io
?我也知道basic %
operations with strings,如%w
,但管道在這裏做什麼?
+1對於googleable「百分比」'管道' –