Stefano Crocco
5/1/2008 2:26:00 PM
On Thursday 01 May 2008, Bill Lear wrote:
> =C2=A0I would think that for any ruby object 'obj', the following should
> hold:
>
> obj =3D=3D YAML::load(YAML::dump(obj))
>
> but this seems to not be the case.
It depends on the =3D=3D methods for the class in question. If you try the =
same=20
using, for example, an array, you'll find that the comparison returns true.=
=20
This happens because Array redefines the =3D=3D method defined in class Obj=
ect,=20
which returns true only if the two operands are the same object. Class=20
Exception, instead, doesn't redefine it, and so the comparison between two=
=20
exceptions will always return false, unless they're the same object. This=20
means that this will return false:
RuntimeError.new('msg') =3D=3D RuntimeError.new('msg')
Since YAML.load creates a new object basing on the contents of its argument=
,=20
the returned Exception is different (according to =3D=3D) from the original.
I hope this helps
Stefano