# GDBM plus classes other than String

**URL:** <https://www.ruby-forum.com/t/gdbm-plus-classes-other-than-string/176000>\
**Category:** Ruby\
**Created:** [September 23, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/gdbm-plus-classes-other-than-string/176000 "2009-09-23T14:38:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_ASBlack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@David\_ASBlack](https://www.ruby-forum.com/u/David_ASBlack)\
**Post date:** [September 23, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/gdbm-plus-classes-other-than-string/176000/1 "2009-09-23T14:38:23Z")

</div>

Hi –

As an offshoot of some playing around with ActiveModel (part of Rails  
3) and adding non-relational database backends to Rails, I’ve spawned  
a little project called GDBMP, which lets you use non-string keys and  
values in GDBM files.

I literally don’t remember why I chose to add “P”.

Anyway, it lets you do things like:

g = GDBMP.new(“/tmp/myfile.gdbmp”)  
g[123] = :abc  
g[:def] = 12.3

etc. The way it works is to store class names along with keys and  
values, and then perform conversions on the way out.

It’s pretty much hard-wired to a handful of classes, and pretty  
simple-minded about the conversions, though you can also constrain  
keys to have their values be of certain classes:

g.constrain\_key(:year, Fixnum)  
g[:year] = “1999”  
g[:year] # 1999 (the integer)

You can find it on github:

[GitHub - dblack/gdbmp: GDBMP -- a subclass of GDBM allowing for keys and values of classes other than String](http://github.com/dblack/gdbmp)

David
