Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Ruby 1.9 中:{1=>2,3=>4}.select{|k,v| v>2}给出{3=>4}
{1=>2,3=>4}.select{|k,v| v>2}
{3=>4}
在 Ruby 1.8 中:{1=>2,3=>4}.select{|k,v| v>2}给出[[3,4]]
[[3,4]]
我怎样才能编写一段简单的代码,可以{3=>4}同时在 1.9和1.8 中提供?
Hash[{1=>2,3=>4}.select{|k,v| v>2}]