【发布时间】:2013-01-27 12:39:19
【问题描述】:
我想知道如何搜索散列数组并根据搜索字符串返回一个值。例如,@contacts 包含哈希元素::full_name、:city 和 :email。变量@contacts(我猜它是一个数组)包含三个条目(可能是行)。以下是我迄今为止根据:city 值进行搜索的代码。但是它不起作用。谁能告诉我发生了什么?
def search string
@contacts.map {|hash| hash[:city] == string}
end
【问题讨论】: