Hi Tom, Are you using the Money gem? If not, I suggest you check it out.
Gareth Townsend http://www.garethtownsend.info > On 2 Jan 2016, at 19:27, Ravi (Tom) Hale <[email protected]> wrote: > > Hi all, > > Me again :) Simon Hildebrandt recommended me to join here as I've been > largely learning / using Ruby in a vacuum (I'm teaching myself while > backpacking planet Earth). It's great to have people to ask these questions - > and well thought-out and clearly written replies coming back. > > I'm working on a program that deals with currency trading. The Currency class > keeps track of all instances so that only one instance of (for example) :AUD > is created. It does this via `private_class_method :new` and a class instance > Hash of (currency_code => instance) to store already created objects. > > I'm trying to work out how to test this class without the tests being > order-dependent. > > I've currently got a spec with: > context 'before the first instance is created' > > This was working just fine until I added some more tests in front of it, > where currency objects were created. > > I see a few options: > 1) Create a Currency.reset! class method to reset the class to the state at > BEGIN > 2) Somehow reset the Currency class to load time in a more elegant way > 3) Get rid of the class variables entirely (and still ensure that only object > per currency code exists) > > I'm fudging with 1) for now to keep in the Green. 3 seems to be cleanest in > terms of textbook OO design, but I can't see how to textbookify this... > > Any suggestions on how to implement 2, 3 (or 4..)? > > Cheers, > Tom > > P.S. Let me know if there is a more appropriate forum to ask questions such > as this > > -- > You received this message because you are subscribed to the Google Groups > "Ruby or Rails Oceania" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/rails-oceania. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/rails-oceania. For more options, visit https://groups.google.com/d/optout.
