Remove a key from list of hashes
Your solution looks overly complex. If I understood it correctly, you want to filter out all unavailable states except if it's the last element. A more declarative and idiomatic Ruby approach would be:

filtered_milestones = milestones.reject.with_index do |milestone, idx| 
  is_last_milestone = (idx == milestones.size - 1)
  milestone[:state] == "unavailable" &amp;&amp; !is_last_milestone
end