Questions tagged «ruby-hash»

14
如何从哈希中删除密钥并在Ruby / Rails中获得剩余的哈希?
要将新的配对添加到哈希,请执行以下操作: {:a => 1, :b => 2}.merge!({:c => 3}) #=> {:a => 1, :b => 2, :c => 3} 有类似的方法可以从哈希中删除密钥吗? 这有效: {:a => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2} 但我希望有这样的东西: {:a => 1, :b => 2}.delete!(:a) #=> {:b => 2} 返回值将是剩余的哈希值,这一点很重要,因此我可以执行以下操作: foo(my_hash.reject! …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.