Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-359

BSON::OrderedHash.delete_if does not work as expected

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.0
    • Affects Version/s: 1.4.0
    • Component/s: None
    • Environment:
      Ruby 1.8.7

      BSON::OrderedHash#delete_if modifies the hash while iterating using each, causing incorrect behavior in Ruby 1.8.7. This was causing a number of tests to fail while integrating MongoDB with another product. I was able to resolve the issue with this monkey patch:

      module BSON
      class OrderedHash

      if RUBY_VERSION < '1.9'
      #BSON::OrderedHash bug
      def delete_if
      keys.each do |k|
      if yield k, self[k]
      delete(k)
      end
      end
      self
      end
      end

      end
      end

            Assignee:
            kbanker Kyle Banker
            Reporter:
            plasticlizard Nathan Stults
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: