# OpenStruct, OpenObject both seg fault, this does not, anything wrong?

**URL:** <https://www.ruby-forum.com/t/openstruct-openobject-both-seg-fault-this-does-not-anything-wrong/120431>\
**Category:** Ruby\
**Created:** [November 16, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/openstruct-openobject-both-seg-fault-this-does-not-anything-wrong/120431 "2007-11-16T21:40:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 16, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/openstruct-openobject-both-seg-fault-this-does-not-anything-wrong/120431/1 "2007-11-16T21:40:41Z")

</div>

Ok, I am using 1.8.6 p110 with rails 1.2.5 and I use alot of  
OpenStructs.  
Well, it seg faults pretty regularly:

> > 0.upto(100) {|n| member.driver\_process\_member}  
> > /usr/lib/ruby/1.8/ostruct.rb:75: [BUG] Segmentation fault  
> > ruby 1.8.6 (2007-09-23) [i686-linux]

So I tried ruby 1.8.5, same thing.  
So I tried OpenObject in the facets lib, seg faults in a different  
place now:

> > member = Account.get(6).member;0.upto(100) {|n| member.driver\_process\_member}  
> > /usr/lib/ruby/gems/1.8/gems/facets-2.1.1/lib/more/facets/openobject.rb:  
> > 183: [BUG] Segmentation fault  
> > ruby 1.8.5 (2006-08-25) [i686-linux]

class HashDot \< Hash  
def method\_missing(sym, arg=nil)  
type = sym.to\_s[-1,1]  
key = sym.to\_s.sub(/[=?!]$/,’’).to\_sym  
if type == “=”  
self[key] = arg  
return self[key]  
else  
return self[key]  
end  
end  
end

So I created this minimalist class that extends hash, and it does not  
segfault.  
The questions are:

- how to figure out what’s wrong with OpenStruct (I am not a gdb guy  
but could follow instructions)
- why is the source for OpenStruct and OpenObject so complicated  
(compared to HashDot)?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 16, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/openstruct-openobject-both-seg-fault-this-does-not-anything-wrong/120431/2 "2007-11-16T22:23:24Z")

</div>

On Nov 16, 3:40 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> place now:  
> key = sym.to\_s.sub(/[=?!]$/,‘’).to\_sym  
> segfault.  
> The questions are:
> 
> - how to figure out what’s wrong with OpenStruct (I am not a gdb guy  
> but could follow instructions)
> - why is the source for OpenStruct and OpenObject so complicated  
> (compared to HashDot)?

They both remove as many Kernel methods as they possibly can in order  
to make the objects as “open” as possible. So my guess is, this must  
be arising from a method that Ruby is expecting to exist (as public)  
but that both classes are clobbering. The question then is which one.  
To help out this is what OpenObject does.

PUBLIC\_METHODS = /(^\_\_|^instance\_|^object\_|^\W|^as$|^send$|^class$|?  
$)/

protected \*public\_instance\_methods.select{ |m| m !~ PUBLIC\_METHODS }

T.
