Project

General

Profile

Feature #4818

Add method marshalable?

Added by yimutang (Joey Zhou) over 8 years ago. Updated almost 2 years ago.

Status:
Assigned
Priority:
Normal
Target version:
-
[ruby-core:36707]

Description

Some objects can not be marshaled. Maybe there should be a method to tell it.

hash = 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) #=> method "Marshal.marshalable?"
hash.marshalable? #=> method "Kernel#marshalable?"

If you think the method name hard to spell, maybe get a synonym "dumpable?"


Related issues

Has duplicate Ruby master - Feature #16240: Are all objects and methods marshalableRejectedActions

History

Updated by naruse (Yui NARUSE) over 8 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

Updated by austin (Austin Ziegler) over 8 years ago

On Fri, Jun 3, 2011 at 1:44 PM, Joel VanderWerf
wrote:

On 06/02/2011 07:07 PM, Joey Zhou wrote:

Some objects can not be marshaled. Maybe there should be a method to tell
it.

hash = 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) #=> method "Marshal.marshalable?"
hash.marshalable? #=> method "Kernel#marshalable?"

What would it do in this case?

hash = Hash.new {|h,k| k * 2}
[hash].marshalable?

So the method needs to recurse arbitrarily deep. So #marshalable will need
to know just as much as Marshal.dump itself does about the object references
contained in an object. Abstracting this out of Marshal.dump will be complex
and will depend on external libraries and gems, which do custom dumping.

Why not just marshal and rescue?

Or:

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

Updated by mame (Yusuke Endoh) about 7 years ago

  • Target version set to 2.6
#4

Updated by naruse (Yui NARUSE) almost 2 years ago

  • Target version deleted (2.6)
#5

Updated by mame (Yusuke Endoh) 2 months ago

  • Has duplicate Feature #16240: Are all objects and methods marshalable added

Also available in: Atom PDF