# Marshal\_load, marshal\_dump

**URL:** <https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583>\
**Category:** Ruby\
**Created:** [December 13, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583 "2008-12-13T23:48:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 13, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/1 "2008-12-13T23:48:42Z")

</div>

Currently RMagick uses the old \_dump and \_load methods to  
marshal/unmarshal images. I’d like to start using the new marshal\_load  
and marshal\_dump methods. What is the impact of switching? Can I just  
replace \_dump and \_load with marshal\_dump and marshal\_load? Suppose I  
have an image that was dumped using an old version of RMagick. How do I  
support loading it?

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 15, 2008, 10:59am UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/2 "2008-12-15T10:59:52Z")

</div>

Hi,

In message “Re: marshal\_load, marshal\_dump”  
on Sun, 14 Dec 2008 07:36:18 +0900, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|Currently RMagick uses the old \_dump and \_load methods to  
|marshal/unmarshal images. I’d like to start using the new marshal\_load  
|and marshal\_dump methods. What is the impact of switching? Can I just  
|replace \_dump and \_load with marshal\_dump and marshal\_load? Suppose I  
|have an image that was dumped using an old version of RMagick. How do I  
|support loading it?

marshal\_dump has high priority over \_dump, so you can keep \_load as  
long as you want backward compatibility.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 16, 2008, 12:14am UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/3 "2008-12-16T00:14:22Z")

</div>

On Dec 13, 2008, at 14:36 PM, Tim H. wrote:

> Currently RMagick uses the old \_dump and \_load methods to marshal/  
> unmarshal images. I’d like to start using the new marshal\_load and  
> marshal\_dump methods. What is the impact of switching? Can I just  
> replace \_dump and \_load with marshal\_dump and marshal\_load? Suppose  
> I have an image that was dumped using an old version of RMagick. How  
> do I support loading it?

Note that \_dump/\_load occurs before allocate and marshal\_dump/  
marshal\_load occurs after. In some instances this is an important  
distinction.

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 16, 2008, 7:31am UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/4 "2008-12-16T07:31:12Z")

</div>

On Dec 15, 2008, at 17:20 PM, Tim H. wrote:

> > distinction.
> 
> Absolutely. I wish I could find some examples of custom marshal\_dump/  
> marshal\_load implementations. Searching thru the 1.8.7/1.9.1 sources  
> didn’t turn up anything illuminating.

Look in RubyGems. Gem::Specification, Gem::Version and  
Gem::Requirement have custom marshal methods.

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 16, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/5 "2008-12-16T13:22:29Z")

</div>

Eric H. wrote:

> > > marshal\_dump/marshal\_load occurs after. In some instances this is an  
> > > important distinction.
> > 
> > Absolutely. I wish I could find some examples of custom  
> > marshal\_dump/marshal\_load implementations. Searching thru the  
> > 1.8.7/1.9.1 sources didn’t turn up anything illuminating.
> 
> Look in RubyGems. Gem::Specification, Gem::Version and Gem::Requirement  
> have custom marshal methods.

Excellent! Thanks for the pointer.

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 16, 2008, 2:28am UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/6 "2008-12-16T02:28:17Z")

</div>

Eric H. wrote:

> important distinction.

Absolutely. I wish I could find some examples of custom  
marshal\_dump/marshal\_load implementations. Searching thru the  
1.8.7/1.9.1 sources didn’t turn up anything illuminating.

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [December 16, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/marshal-load-marshal-dump/155583/7 "2008-12-16T20:04:05Z")

</div>

Tim H. wrote:

> Absolutely. I wish I could find some examples of custom  
> marshal\_dump/marshal\_load implementations. Searching thru the  
> 1.8.7/1.9.1 sources didn’t turn up anything illuminating.

A very simple one:

class C  
attr\_accessor :x, :y

def marshal\_dump  
[x, y]  
end

def marshal\_load(ary)  
@x, @y = ary  
end  
end

c = C.new  
c.x = “foo”  
c.y = “bar”

s = Marshal.dump©  
p Marshal.load(s)
