B
Brent Dillingham
Hi all,
For fun, I'm writing a MUD with Ruby. I thought I'd query the hive
mind here and ask some opinions on what library I might use for object
persistence -- that is, storing objects like players and rooms
somewhere.
I could do something really simple like store everything in YAML, I
could try DRb, or I could go all out and use an ORM like DataMapper...
DataMapper is the first route I took, but I soon realized that I'll
have to be really careful when using a lot of the ORM niceties while
still ensuring that a database row only every represents one object in
memory. i.e.:
# assuming Player has_one :room ...
player = Player.get(1) # get Player with ID=1
player.room # the player's current Room association
... player logs out, logs back in later ...
player.room
Oh noes! The ORM fetches the same room from the DB, but creates a
totally new object to represent it. Two players could be in the same
room ID, but actually reference different objects, and thus couldn't
see or interact with one another. Bad.
This problem is hackable by carefully keeping a cache of loaded
objects -- but might end up negating the value of using an ORM like
DataMapper. So, any suggestions out there of what I might do instead?
Thanks! ^_^
For fun, I'm writing a MUD with Ruby. I thought I'd query the hive
mind here and ask some opinions on what library I might use for object
persistence -- that is, storing objects like players and rooms
somewhere.
I could do something really simple like store everything in YAML, I
could try DRb, or I could go all out and use an ORM like DataMapper...
DataMapper is the first route I took, but I soon realized that I'll
have to be really careful when using a lot of the ORM niceties while
still ensuring that a database row only every represents one object in
memory. i.e.:
# assuming Player has_one :room ...
player = Player.get(1) # get Player with ID=1
player.room # the player's current Room association
... player logs out, logs back in later ...
player.room
Oh noes! The ORM fetches the same room from the DB, but creates a
totally new object to represent it. Two players could be in the same
room ID, but actually reference different objects, and thus couldn't
see or interact with one another. Bad.
This problem is hackable by carefully keeping a cache of loaded
objects -- but might end up negating the value of using an ORM like
DataMapper. So, any suggestions out there of what I might do instead?
Thanks! ^_^