I’m currently working with a ruby hash that looks like the following:
{"employee"=>[{"name"=>"john", "level"=>"1", "position"=>"S1"},
{"name"=>"bill", "level"=>"2", "position"=>"S2"}]}
These are two examples of employees and I need to be able to pull employees out by values. For example I’d like to get all employees who’s level == 2, or all employees who’s position == S1.
How would I do this in Ruby?
Use
Hash#selectorArray#select.This will return an array of employee info hashes according to your criteria. Be sure to put quotes around value for level