Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3764

Mongoid::Relations::Targets::Enumerable get skipped in case statement

    • Type: Icon: Task Task
    • Resolution: Done
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      I wrote a helper method to get attributes hash/hashes out of some known data types like this

      case obj
      when Hash then obj
      when Mongoid::Relations::Targets::Enumerable, 
           Array,
           Mongoid::Criteria then obj.map(&:attrs)
      when Error, Mongoid::Document then obj.attrs
      end
      

      while obj.class == Mongoid::Relations::Targets::Enumerable the second branch get skipped. I dug into the code, found === method had been overridden:

      def ===(other)
        other.class == Class ? Array == other : self == other
      end
      

      such that its instances cannot match it in a case statement.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kaid kaid
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: