Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't delete from ENV while iterating

  • Loading branch information...
commit 15dae5bbcd848efcc43d739ce6e9e422f874dd1b 1 parent 5d33d53
@jfirebaugh jfirebaugh authored
Showing with 7 additions and 8 deletions.
  1. +7 −8 kernel/common/env.rb
View
15 kernel/common/env.rb
@@ -121,15 +121,14 @@ def reject(&block)
def reject!
return to_enum(:reject!) unless block_given?
- rejected = false
- each do |k, v|
- if yield(k, v)
- delete k
- rejected = true
- end
- end
+ # Avoid deleting from environ while iterating because the
+ # OS can handle that in a million different bad ways.
+
+ keys = []
+ each { |k, v| keys << k if yield(k, v) }
+ keys.each { |k| delete k }
- rejected ? self : nil
+ keys.empty? ? nil : self
end
def clear
Please sign in to comment.
Something went wrong with that request. Please try again.