[英]Ruby: Is there a better way to write the following method?
是否有更好的方法來編寫以下方法(如果可能,將其轉換為單行?)。
def create_array(opts)
array = []
opts.each{|key,value| array << value}
array
end
如果opts
是hash
那么試試吧:
def create_array(opts)
opts.values
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.