On Fri, Jun 3, 2011 at 1:44 PM, Joel VanderWerf
<joelvanderwerf / gmail.com> wrote:
> On 06/02/2011 07:07 PM, Joey Zhou wrote:
>> Some objects can not be marshaled. Maybe there should be a method to tel=
l
>> it.
>>
>> hash =3D Hash.new {|h,k| k * 2}
>>
>> this hash can't be marshaled because it has a default proc. If existing
>> such method:
>> Marshal.marshalable?(hash) #=3D> =A0method "Marshal.marshalable?"
>> hash.marshalable? #=3D> =A0method "Kernel#marshalable?"
>
> What would it do in this case?
>
> hash =3D Hash.new {|h,k| k * 2}
> [hash].marshalable?
>
> So the method needs to recurse arbitrarily deep. So #marshalable will nee=
d
> to know just as much as Marshal.dump itself does about the object referen=
ces
> contained in an object. Abstracting this out of Marshal.dump will be comp=
lex
> and will depend on external libraries and gems, which do custom dumping.
>
> Why not just marshal and rescue?

Or:

hash =3D Hash.new { |h, k| h[k] =3D k * 2 }
class << hash
  def marshal_dump
    Hash[*self.to_a]
end
hash.marshalable? # =3D> true

-a
--=20
Austin Ziegler =95 halostatue / gmail.com =95 austin / halostatue.ca
http://www.halostatue.ca/ =95 http://twitter.com/halostatue