# Serialized object behaves weird

**URL:** <https://www.ruby-forum.com/t/serialized-object-behaves-weird/97172>\
**Category:** Rails\
**Created:** [July 5, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/serialized-object-behaves-weird/97172 "2006-07-05T13:41:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [July 5, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/serialized-object-behaves-weird/97172/1 "2006-07-05T13:41:11Z")

</div>

Hi!

I got a class named EinsatzFilter which I serialized to session. Before  
saving to session it works afterwards I keep getting the message:  
“undefined method `to\_s’ for #Person:0x38c6ab8”. “Person” is a from  
ActiveRecord::Base inherited class.

Code:

class EinsatzFilter  
include ApplicationHelper

attr\_reader :personen, :monat, :projekte, :kunde  
attr\_writer :personen, :monat, :projekte, :kunde

ATTRIBUTES = [  
[‘personen’, ‘person\_id’, ‘Personen’, Person],  
[‘projekte’, ‘projekt\_id’, ‘Projekte’, Projekt],  
]

def initialize(attrs = nil)  
attrs.each {|k,v| self.send(k + ‘=’, v) } unless attrs.nil?  
end

def to\_s  
ret = String.new  
ATTRIBUTES.each {|attr|  
vals = self.send(attr[0])  
ret \<\< (ret.empty? ? “” : "; ") + attr[2] + ": " +   
make\_list(vals.collect{|val| val.to\_i },attr[3]) unless  
vals.nil?  
}  
ret  
end

# Erzeugt aus dem Filter ein Array zur Ã?bergabe als :condition an

# ActiveRecord::Base.find.

# RÃ¼ckgabewert kÃ¶nnte z.B. sein:

# [“person\_id in (?) and projekt\_id in (?)”, [2, 3], [1, 2, 3]]

# 

# :call-seq:

# find(:Einsatz, :conditions =\> @einsatz\_filter.conditions)

# 

def conditions  
ret = Array.new(1, ‘’)  
attrs = ATTRIBUTES.collect {|attr|  
attr = [self.send(attr[0]), attr[1]]  
}  
attrs.each {|obj|  
unless obj[0].nil?  
ret[0] \<\< " and " unless ret[0].empty?  
ret[0] \<\< “#{obj[1]} in (?)”  
ret \<\< obj[0].collect{|x| x.to\_i}  
end  
}  
return ret unless ret.length == 1  
end

private  
def make\_list(arr, obj)  
ret = ‘’  
obj.find(arr).each {|p|  
ret \<\< ', ’ unless ret.length == 0  
ret \<\< p.to\_s  
}  
ret  
end  
end

class Person \< ActiveRecord::Base  
has\_many :Einsatz

def to\_s  
self.name  
end  
end

What’s my problem?

Greetings,  
Alex.

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [July 6, 2006, 8:53am UTC](https://www.ruby-forum.com/t/serialized-object-behaves-weird/97172/2 "2006-07-06T08:53:46Z")

</div>

I wrote:

> def make\_list(arr, obj)  
> ret = ‘’  
> obj.find(arr).each {|p|  
> ret \<\< ', ’ unless ret.length == 0  
> ret \<\< p.to\_s  
> }  
> ret  
> end  
> end

I finally got it, but I am not clearly about the problem. I had to  
change “obj.find” to “eval(obj).find”.

Please could someone explain that to me?

Alex.

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [July 5, 2006, 2:40pm UTC](https://www.ruby-forum.com/t/serialized-object-behaves-weird/97172/3 "2006-07-05T14:40:53Z")

</div>

If I ask before this exception appears I get the following array  
including “to\_s”:

“require\_gem\_with\_options”, “after\_find”, “cattr\_accessor”, “const\_set”,  
“delete\_observers”, “parents”, “read\_methods”, “extend”,  
“encode\_quoted\_value”, “validates\_numericality\_of”, “l\_has\_string?”,  
“construct\_calculation\_sql”, “active\_connection\_name”,  
“set\_readonly\_option!”, “after\_update”, “set\_inheritance\_column”,  
“deprecated\_has\_association\_method”, “sum”, “serialize”, “frozen?”,  
“pluralize\_table\_names”, “has\_many”, “count\_observers”, “to\_a”,  
“delete\_all”, “extended\_by”, “pluralize\_table\_names=”,  
“before\_validation”, “set\_language”,  
“deprecated\_association\_comparison\_method”,  
“thread\_safe\_scoped\_methods”, “connected?”, “lock\_optimistically”,  
“const\_defined?”, “l\_time”, “validate\_on\_create”, “is\_complex\_yaml?”,  
“has\_and\_belongs\_to\_many”, “lock\_optimistically=”, “as\_load\_path”,  
“reset\_column\_information\_and\_inheritable\_attributes\_for\_all\_subclasses”,  
“unlock\_mutex”, “class\_inheritable\_reader”, “sqlite3\_connection”,  
“destroy”, “table\_exists?”, “to\_s”, “nil?”,  
“copy\_instance\_variables\_from”, “clear\_active\_connection\_name”,  
“to\_yaml\_properties”, “after\_validation”, “included\_modules”,  
“single\_threaded\_scoped\_methods”, “respond\_to?”, “set\_locking\_column”,  
“current\_scoped\_methods”, “serialized\_attributes”, “colorize\_logging”,  
“scope”, “validate\_on\_update”, “create!”, “postgresql\_connection”,  
“human\_attribute\_name”, “class\_inheritable\_writer”, “const\_missing”,  
“has\_one”, “inspect”, “update\_all”, “equal?”, “load”,  
“colorize\_logging=”, “reflect\_on\_aggregation”, “set\_language\_if\_valid”,  
“reset\_column\_information”, “find\_on\_conditions”,  
“before\_validation\_on\_create”, “find\_by\_sql”, “reset\_locking\_column”,  
“remove\_subclasses”, “reset\_table\_name”, “l\_YesNo”,  
“class\_inheritable\_array\_writer”, “class\_variables”, “belongs\_to”,  
“methods”, “daemonize”, “include?”, “timestamps\_gmt”, “eql?”, “require”,  
“retrieve\_connection”, “method\_defined?”, “columns”, “name”,  
“after\_validation\_on\_create”, “acts\_as\_tree”, “hash”, “calculate”,  
“validates\_size\_of”, “timestamps\_gmt=”, “remove\_subclasses\_of”,  
“scoped\_methods”, “condition\_block?”, “find”,  
“deprecated\_find\_in\_collection\_method”, “changed?”, “method”,  
“default\_timezone”, “evaluate\_condition”, “to\_yaml”,  
“class\_inheritable\_hash\_writer”, “create\_reflection”,  
“silence\_warnings”, “singleton\_methods”, “display”, “logger”,  
“default\_timezone=”, “compute\_type”, “autoload”,  
“public\_method\_defined?”, “ancestors”, “before\_validation\_on\_update”,  
“id”, “db2\_connection”, “connection”, “class\_name”,  
“class\_name\_of\_active\_record\_descendant”, “validates\_uniqueness\_of”,  
“exists?”, “average”, “with\_exclusive\_scope”, “subclasses”,  
“verification\_timeout”, “logger=”, “base\_class”,  
“descends\_from\_active\_record?”,  
“deprecated\_find\_all\_in\_collection\_method”, “connection=”,  
“validates\_each”, “sanitize”, “class\_inheritable\_accessor”,  
“verification\_timeout=”, “superclass”, “clear\_active\_connections!”,  
“protected\_methods”, “destroy\_all”, “openbase\_connection”,  
“acts\_as\_list”, “extend\_with\_included\_modules\_from”,  
“private\_method\_defined?”, “after\_validation\_on\_update”,  
“firebird\_connection”, “ **id** ”, “replace\_named\_bind\_variables”,  
“subclasses\_of”, “find\_all”, “set\_table\_name”,  
“deprecated\_collection\_create\_method”, “l\_yesno”, “allow\_concurrency”,  
“benchmark”, “autoload?”, “class\_inheritable\_array”, “private\_methods”,  
“enable\_warnings”, “count\_by\_sql”, “instance\_values”, “\<=\>”,  
“protected\_method\_defined?”, “reset\_subclasses”, “allow\_concurrency=”,  
“==”, “before\_destroy”, “included\_in\_classes”, “object\_id”,  
“transaction”, “table\_name”, “\<”, “===”, “replace\_bind\_variables”,  
“public\_class\_method”, “sanitize\_sql”, “threaded\_connections”,  
“remove\_class”, “sqlserver\_connection”, “observers=”, “\>”, “\>=”,  
“deprecated\_collection\_build\_method”, “reset\_primary\_key”,  
“table\_name=”, “\<=”, “instance\_method”, “threaded\_connections=”,  
“class\_inheritable\_hash”, “verify\_active\_connections!”, “delete”,  
“public\_methods”, “silence\_stderr”, “sanitize\_conditions”, “=~”,  
“instance\_exec”, “l\_age”, “after\_destroy”, “columns\_hash”, “type”,  
“private\_class\_method”, “class\_of\_active\_record\_descendant”,  
“current\_language”, “create”, “encode64”, “validates\_confirmation\_of”,  
“rails\_original\_const\_missing”, “generate\_read\_methods”, “allocate”,  
“inheritable\_attributes”, “composed\_of”, “instance\_variables”,  
“silence\_stream”, “sqlite\_connection”, “configurations”,  
“generate\_read\_methods=”, “validate”, “class”, “module\_eval”,  
“instantiate”, “raise\_if\_bind\_arity\_mismatch”, “parent”,  
“thread\_safe\_active\_connections”, “configurations=”, “abstract\_class”,  
“ll”, “set\_primary\_key”, “l\_lang\_name”, “count”, “abstract\_class=”,  
“instance\_variable\_get”, “blank?”, “increment\_counter”, “returning”,  
“acts\_as\_nested\_set”, “mattr\_reader”, “column\_names”,  
“instance\_methods”, “clone”, “decode\_b”, “class\_eval”,  
“deprecated\_collection\_count\_method”, “validates\_format\_of”,  
“single\_threaded\_active\_connections”, “ltry”, “inheritance\_column”,  
“update”, “after\_initialize”, “decode64”, “schema\_format”, “inherited”,  
“reflections”, “write\_inheritable\_attribute”, “instance\_variable\_set”,  
“inheritance\_column=”, “ **send** ”, “with\_options”, “l\_date”,  
“primary\_key\_prefix\_type”, “schema\_format=”, “mattr\_writer”,  
“abstract\_class?”, “public\_instance\_methods”, “dup”,  
“deprecated\_add\_association\_relation”, “primary\_key”,  
“quote\_bound\_value”, “primary\_key\_prefix\_type=”, “active\_connections”,  
“sequence\_name”, “new”, “before\_save”, “primary\_key=”,  
“validates\_acceptance\_of”, “`”, “class\_inheritable\_option”,  
“write\_inheritable\_array”, “reflect\_on\_all\_aggregations”, “suppress”,  
“oracle\_connection”, “decrement\_counter”, “sequence\_name=”,  
“l\_strftime”, “content\_columns”, “protected\_instance\_methods”,  
“changed”, “mattr\_accessor”, “taint”,  
“deprecated\_remove\_association\_relation”, “validates\_inclusion\_of”,  
“reset\_sequence\_name”, “after\_save”, “lwr”, “send”, “find\_first”,  
“with\_scope”, “mysql\_connection”, “attr\_protected”,  
“connection\_without\_query\_cache=”, “instantiate\_with\_callbacks”,  
“to\_json”, “table\_name\_prefix”, “require\_gem”, “lock\_mutex”,  
“cattr\_reader”, “private\_instance\_methods”, “notify\_observers”,  
“delegate”, “to\_yaml\_type”, “validates\_exclusion\_of”,  
“record\_timestamps”, “reloadable?”, “deprecated\_has\_collection\_method”,  
“table\_name\_prefix=”, “before\_create”, “lwr\_”, “instance\_of?”,  
“instance\_eval”, “validates\_presence\_of”, “record\_timestamps=”,  
“read\_inheritable\_attribute”, “reflect\_on\_all\_associations”,  
“locking\_column”, “protected\_attributes”, “tainted?”, “scoped?”,  
“establish\_connection”, “l\_datetime”, “column\_methods\_hash”,  
“constants”, “quote”, “untaint”, “b64encode”, “validates\_associated”,  
“execute\_grouped\_calculation”, “extract\_options\_from\_args!”,  
“set\_sequence\_name”, “after\_create”, “kind\_of?”, “method\_added”,  
“validates\_length\_of”, “validate\_find\_options”,  
“write\_inheritable\_hash”, “l”, “oci\_connection”, “attr\_accessible”,  
“minimum”, “table\_name\_suffix”, “add\_observer”, “cattr\_writer”,  
“const\_get”, “reflect\_on\_association”, “delete\_observer”, “freeze”,  
“execute\_simple\_calculation”, “log\_connections”, “table\_name\_suffix=”,  
“silence”, “before\_update”, “is\_a?”, “reset\_inheritable\_attributes”,  
“require\_library\_or\_gem”, “accessible\_attributes”, “maximum”,  
“remove\_connection”, “l\_datetime\_short”
