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

BSON::OrderedHash.delete_if does not work as expected

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.5.0
    • Component/s: None
    • Labels:
    • Environment:
      Ruby 1.8.7

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: