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

Serializing a custom type has Sideeffects

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

      When you include Mongoid::Fields::Serializable in a class, the following code within this class will now return false instead of true: {}.is_a?(Hash)

      This happens because with the inclusion of Serializable the 'nearest' Hash-Class will be 'Mongoid::Fields::Serializable::Hash'.

      Naturally this is not the behaviour someone would expect.

      The following Code illustrates the problem:

      class TestIt
      include Mongoid::Fields::Serializable

      def is_hash
      if( {}.is_a?(::Hash) )
      puts "hash: right"
      else
      puts "hash: wrong"
      end
      end

      def is_array
      if( [].is_a?(Array) )
      puts "array: right"
      else
      puts "array: wrong"
      end
      end
      end

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

              Created:
              Updated:
              Resolved: