# Stupid Newb Question

**URL:** <https://rubytalk.org/t/stupid-newb-question/20761>\
**Category:** ruby-talk\
**Created:** [12 September 2005 11:11 UTC](https://rubytalk.org/t/stupid-newb-question/20761 "2005-09-12T11:11:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_O\_Connell](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@Derek\_O\_Connell](https://rubytalk.org/u/Derek_O_Connell)\
**Post date:** [12 September 2005 11:11 UTC](https://rubytalk.org/t/stupid-newb-question/20761/1 "2005-09-12T11:11:32Z")

</div>

For background only (I think my question is simple): I'm new to ruby,  
read the book etc and now trying my first conversion. I'm doing this in  
two stages since I'm still getting familiar with Ruby syntax. First stage  
is to take my existing PureBasic code (think C without any of the junk)  
and try to implement the Ruby equivalent line-for-line. Second stage I'll  
completely redesign it in true Ruby fashion. My PB program is an  
automated downloader where I supply a list of URL's and the "Download  
Manager" (DLM) part handles "Requests" by creating a thread for each one.  
The DLM itself is a thread so I can schedule the downloads say every 10  
mins. Now my question...

So far I have created classes for the DLM and Requests. To track the  
states of both I use constants declared (in PB), for example as...

#DLM\_MS\_INACTIVE = 0  
#DLM\_MS\_RUNNING = 1  
#DLM\_MS\_PAUSED = 2

Another way, used in other parts of my code, is PB's enums...

Enumeration  
&nbsp;&nbsp;#DLM\_MS\_INACTIVE  
&nbsp;&nbsp;#DLM\_MS\_RUNNING  
&nbsp;&nbsp;#DLM\_MS\_PAUSED  
EndEnumeration

....which does the same thing (in this case I don't care about the actual  
values).

So what is the nearest Ruby equivalent? I'd want it class-specific so I  
don't need the DLM\_MS\_ part and where I don't care about the actual value  
I guess I'd use symbols? Any/all tips appreciated!

PS: I already know that when I do a proper redesign I'll probably use  
queues to represent the states of individual requests. My problem of how  
best to represent/implement constants/enums extends to other code I want  
to convert.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [12 September 2005 11:21 UTC](https://rubytalk.org/t/stupid-newb-question/20761/2 "2005-09-12T11:21:32Z")

</div>

Derek O'Connell wrote:

> For background only (I think my question is simple): I'm new to ruby,  
> read the book etc and now trying my first conversion. I'm doing this  
> in two stages since I'm still getting familiar with Ruby syntax.  
> First stage is to take my existing PureBasic code (think C without  
> any of the junk) and try to implement the Ruby equivalent  
> line-for-line. Second stage I'll completely redesign it in true Ruby  
> fashion. My PB program is an automated downloader where I supply a  
> list of URL's and the "Download Manager" (DLM) part handles  
> "Requests" by creating a thread for each one. The DLM itself is a  
> thread so I can schedule the downloads say every 10 mins. Now my  
> question...
> 
> So far I have created classes for the DLM and Requests. To track the  
> states of both I use constants declared (in PB), for example as...
> 
> #DLM\_MS\_INACTIVE = 0  
> #DLM\_MS\_RUNNING = 1  
> #DLM\_MS\_PAUSED = 2
> 
> Another way, used in other parts of my code, is PB's enums...
> 
> Enumeration  
> &nbsp;&nbsp;#DLM\_MS\_INACTIVE  
> &nbsp;&nbsp;#DLM\_MS\_RUNNING  
> &nbsp;&nbsp;#DLM\_MS\_PAUSED  
> EndEnumeration
> 
> ...which does the same thing (in this case I don't care about the  
> actual values).
> 
> So what is the nearest Ruby equivalent? I'd want it class-specific so  
> I don't need the DLM\_MS\_ part and where I don't care about the actual  
> value I guess I'd use symbols? Any/all tips appreciated!
> 
> PS: I already know that when I do a proper redesign I'll probably use  
> queues to represent the states of individual requests. My problem of  
> how best to represent/implement constants/enums extends to other code  
> I want to convert.

You can define constants per class, you can use an existing enum  
implementation (to be found in the RAA) or you can directly use symbols.  
Disadvantage of the latter approach is documentation: you don't have a  
single place where all are defined.

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

---

<div class="post-metadata">

**Author:** ![Derek\_O\_Connell](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@Derek\_O\_Connell](https://rubytalk.org/u/Derek_O_Connell)\
**Post date:** [12 September 2005 11:46 UTC](https://rubytalk.org/t/stupid-newb-question/20761/3 "2005-09-12T11:46:32Z")

</div>

Thanks Robert. Think I'll use class constants for now.

---

<div class="post-metadata">

**Author:** ![Jon\_A\_Lambert2](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@Jon\_A\_Lambert2](https://rubytalk.org/u/Jon_A_Lambert2)\
**Post date:** [19 September 2005 07:44 UTC](https://rubytalk.org/t/stupid-newb-question/20761/4 "2005-09-19T07:44:14Z")

</div>

Robert Klemme wrote:

> You can define constants per class, you can use an existing enum  
> implementation (to be found in the RAA) or you can directly use  
> symbols. Disadvantage of the latter approach is documentation: you  
> don't have a single place where all are defined.

I love :symblos

However, the above is another disadvantage.

If you misspell one, noone :screams about it, and they have such tiny :colons they are hard to :spot.

> **···**
>
> --  
> J Lambert
