我需要以某种方式增加价值:
sizes = { :thumb => ["100x100"] }
现有的哈希。
问题是,:thumb
的含义是一个变量,所以制作
sizes[@thumb] = ["100x100"]
# or
sizes.merge!(@thumb=>["100x100"])
# the result is:
> sizes = { "thumb" => ["100x100"] }
我的应用"thumb"
不被接受。它需要提供:thumb
密钥格式。我怎么能这样做?
答案 0 :(得分:1)
怎么样:
sizes[@thumb.to_sym] = ["100x100"]
# or
sizes.merge!(@thumb.to_sym => ["100x100"])