# Serializing a Proc doesn't seem to work

**URL:** <https://www.ruby-forum.com/t/serializing-a-proc-doesnt-seem-to-work/111426>\
**Category:** Rails\
**Created:** [August 7, 2007, 8:06am UTC](https://www.ruby-forum.com/t/serializing-a-proc-doesnt-seem-to-work/111426 "2007-08-07T08:06:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Astorian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@Astorian](https://www.ruby-forum.com/u/Astorian)\
**Post date:** [August 7, 2007, 8:06am UTC](https://www.ruby-forum.com/t/serializing-a-proc-doesnt-seem-to-work/111426/1 "2007-08-07T08:06:05Z")

</div>

In Agile Web D. with Rails, there is a section on serializing  
Ruby objects.

“We can assign any Ruby object to the last\_five column” … p312

When I attempt to do this with a proc object, something like this is  
saved in the db

— !ruby/object:Proc {}

Obviously, this doesn’t do much, and I attempt to use it …

NoMethodError: undefined method `call’ for “— !ruby/object:Proc {}\n  
\n”:String  
from (irb):5

Is it possible to save Proc objects in the db?

I am implementing a custom field scheme, where users can create custom  
fields. I have Field Types, and I was thinking about using a ruby proc  
to convert field entries to the correct object type.

John

---

<div class="post-metadata">

**Author:** ![Astorian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@Astorian](https://www.ruby-forum.com/u/Astorian)\
**Post date:** [August 7, 2007, 6:16pm UTC](https://www.ruby-forum.com/t/serializing-a-proc-doesnt-seem-to-work/111426/2 "2007-08-07T18:16:01Z")

</div>

Astorian wrote:

> In Agile Web D. with Rails, there is a section on serializing  
> Ruby objects.
> 
> “We can assign any Ruby object to the last\_five column” … p312
> 
> When I attempt to do this with a proc object, something like this is  
> saved in the db
> 
> — !ruby/object:Proc {}
> 
> Obviously, this doesn’t do much, and I attempt to use it …
> 
> NoMethodError: undefined method `call’ for “— !ruby/object:Proc {}\n  
> \n”:String  
> from (irb):5
> 
> Is it possible to save Proc objects in the db?
> 
> I am implementing a custom field scheme, where users can create custom  
> fields. I have Field Types, and I was thinking about using a ruby proc  
> to convert field entries to the correct object type.

“any” must be taken with a grain of salt. Only objects that have a  
serializable state can be saved that way. You couldn’t serialize a  
thread, for instance, or in your case, a proc.

You can use Ruby2Ruby to get the source for a proc, then you can eval it  
when you deserialize it to get an equivalent proc back. It may be easier  
for you to store some other information in the db to do your custom  
field converstion. What you are proposing sounds pretty unwieldy to me.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)
