mongoid/mongoid — Issue #1480: Serializing a custom type has Sideeffects
Author: jak4
Created: 2011-12-06 14:56:46+00:00
State: open

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