Say I have this:
[ { :id => 34, :votes_count => 3 }, { :id => 2, :votes_count => 0 }, ]
How to get id based index? What I want to do is return 0 when searching for id: 34 and 1 when searching for id: 2 . What is the most effective way?
id
0
id: 34
1
id: 2
You can pass the #index block:
#index
array.index {|h| h[:id] == 34 } # => 0