From: Robert Klemme Date: 2005-09-12T20:21:32+09:00 Subject: Re: Stupid Newb Question 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 > #DLM_MS_INACTIVE > #DLM_MS_RUNNING > #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 robert