# Assign dynamic (incrementable) values to objects

**URL:** <https://www.ruby-forum.com/t/assign-dynamic-incrementable-values-to-objects/167251>\
**Category:** Rails\
**Created:** [May 5, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/assign-dynamic-incrementable-values-to-objects/167251 "2009-05-05T23:50:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [May 5, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/assign-dynamic-incrementable-values-to-objects/167251/1 "2009-05-05T23:50:53Z")

</div>

I am working on a registration form for users.  
Users can sign up to attend some sport events and are automatically  
assigned a starting number depending on the users type.

There are several types of users and all have a specific range of  
starting numbers.

0001 - 0050: not automatically assigend  
0051 - 0600: type 1  
0601 - 0650: type 2  
1000 - 1300: type 3  
…

What would be the best practice, to assign these values to a user and  
increment the right counter?

Storing these values in a database table might be a little tricky.  
I also could save the configuration in a yaml file, load it from there  
and write it back. But what about multiple reads and writes at the  
same time. Can this be handled by a message queue, which ensures that  
the file (or database table) is sequentially accessed?

Thanks for any comment!
