I have a Ruby hash:
@tags = { "project_status" => { "title" => "Project status" },
"milestones" => { "title" => "Milestones"},
"lessons" => { "title" => "Lessons"},
"tasks" => { "title" => "Tasks"} }
I’d like to shift specific key-value pairs out of this hash.
e.g. if I am interested in "milestones" tags, then shift on the hash will give me:
=> ["milestones", {"title"=>"Milestones"}]
Which is exactly what I want.
Except that I can’t work out how to select a specific key-value pair.
I could write something to iterate through the hash until I find the matching key and then call shift, but I’m assuming there’s a cleaner “Ruby way” to do this 🙂
deleteis probably what you’re looking for. It removes corresponding key from the hash (whereasshiftremoves item from an array)