我使用的bash腳本內的代碼來構建在節的輸出:
box_full() {
printf '*%.0s' $(seq 1 67)
echo ""
}
box_content() {
echo -n "*"
if [ $# -eq 0 ]
then
printf ' %.0s' $(seq 1 65)
elif [ $# -eq 1 ]
then
RIGHT="$1"
printf ' %.0s' $(seq 1 17)
echo -n "${RIGHT}"
printf ' %.0s' $(seq 1 $[48-${#RIGHT}])
elif [ $# -eq 2 ]
then
LEFT="$1"
RIGHT="$2"
printf ' %.0s' $(seq 1 3)
echo -n "${LEFT}"
printf ' %.0s' $(seq 1 $[14-${#LEFT}])
echo -n "${RIGHT}"
printf ' %.0s' $(seq 1 $[48-${#RIGHT}])
fi
echo "*"
}`
的使用是:
box_full
box_content "Download-Process..."
box_full`
有沒有辦法用Ruby腳本來做到這一點?
編輯:我第一個走過來解決:
module Style
def self.box_full
puts '*' * 67
end
def self.box_content(content)
box_rest = 66 - content.length
box_rest.to_i
print '* ' + box_rest * '' + '*'
end
end
所以整箱的作品好。
對於第二個我想給方法框內容的字符串稱爲內容。其實它不起作用。所希望輸出爲:
* content *
最後*應該對地方67 行的末尾來設置是否有可能解決在Ruby中?
'$ [arith_expr ]'沒有記錄。使用'$((...))'代替 –