Hash#select!()是一个Hash类方法,它根据块条件检查是否存在来自哈希函数的数组。
用法:Hash.select!()
参数:散列值
封锁条件
返回:基于块条件存在来自哈希的数组,否则返回false
范例1:
# Ruby code for Hash.select!() method
# declaring Hash value
a = { "a" => 100, "b" => 200 }
# declaring Hash value
b = {"a" => 100}
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
# select! Value
puts "Hash a select! form:#{a.select! {|key, value| key < "b"}}\n\n"
输出:
Hash a select! form:{"a"=>100}
范例2:
# Ruby code for Hash.select!() method
# declaring Hash value
b = {"a" => 100}
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
# select! Value
puts "Hash b select! form:#{b.select!{|key, value| value < 200}}\n\n"
puts "Hash c select! form:#{c.select!{|key, value| key < "b"}}\n\n"
输出:
Hash b select! form: Hash c select! form:{"a"=>100}
相关用法
- Ruby Hash select()用法及代码示例
- Ruby Hash value?用法及代码示例
- Ruby Hash reject用法及代码示例
- Ruby Hash to_s用法及代码示例
- Ruby String hash用法及代码示例
- Ruby Hash reject!用法及代码示例
- Ruby Hash values_at用法及代码示例
- Ruby Hash replace()用法及代码示例
- Ruby Hash length()用法及代码示例
- Ruby Hash store()用法及代码示例
- Ruby Hash size()用法及代码示例
注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 Ruby | Hash select!() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。