0
我有哈希值的數組看起來像這樣:追加「 n」來,除了最後的所有元素在Ruby中數組
texts = [{:text => 'my text', :width => 123}, {:text => 'my other text', :width => 200}]
我想有一個最後文本應該是這樣的:
my_final_text = 'my text\nmy other text'
我也試着這樣做:
def concat_breakline(texts)
final_text = ""
texts.each do |text|
final_text << text[:text] + "\n"
end
end
但是,這將增加「\ n」來最後一個元素,我想避免這種情況。我怎麼能解決這個問題?