我尝试在我的应用中只使用 :symbols 作为关键词。我尝试在 :symbol => logic 或 string => UI/language specific 之间做出严格的决定
但我也得到了每个 JSON 的一些“值”(即选项等),因为 JSON 中没有 :symbols,所以我调用的所有哈希都具有“with_indifferent_access”属性。
但是:数组是否有相同的东西?像那样
a=['std','elliptic', :cubic].with_indifferent_access
a.include? :std => true
?
编辑:将 rails 添加到标签
最佳答案
a = ['std','elliptic', :cubic].map(&:to_sym)
a.include? :std
#=> true
编辑 - 关于 maxigs 的评论可能更好地转换为字符串:
a = ['std', 'elliptic', :cubic].map(&:to_s)
a.include? "std"
#=> true
关于ruby-on-rails - 是否有类似 'with_indifferent_access' 的数组可用于包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21816139/