[英]How do I split an array into a bunch of strings in Ruby?
此方法接受URL列表:
Magick::ImageList.new("img1url", "img2url", "img3url")
我有這個字符串"url1, url2, url3"
。
如何將上述方法作為單獨的參數提供給列表? 我試過了:
urls = urls.split(',')
Magick::ImageList.new(urls) # fails. It produces an array.
# fails. It produces "'img1url','img2url'".
# The comma is part of the string, but it should split method arguments.
urls = urls.split(',').join("','")
Magick::ImageList.new(urls)
*
可以將數組擴展為參數:
urls = urls.split(', ')
Magick::ImageList.new(*urls)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.