From: Robert Klemme Date: 2006-03-10T18:18:44+09:00 Subject: Re: [Newbie] Immutable objects Einar wrote: > Thanks - this is starting to feel like playing an adventure game where > the map of the terrain becomes visible as I explore it (or rather: as > you tell me about it). It looks like symbols are appropriate here. I'm > thinking the same might be the case for rank (e.g. "card value" from 2 > up to ace). It might look weird for the numeric values (e.g. :2 or :3 > - which might not even be legal? but then :two and :three would), but > not so for e.g. :jack or :queen. Alternatively you could use constants module Deck JACK = "jack".freeze QUEEN = "queen".freeze ... end But IMHO symbols are more elegant here. OTOH you can define a specialized class for this which also holds numeric values module Deck CARD = Struct.new :name, :value def self.card(name, val) CARD.new(name.freeze,val).freeze end QUEEN = card "queen", 10 JACK = card "jack", 11 ACE = card "ace", 100 ... end > I'm a bit ambivalent on the strictness issue. I buy your arguments for > a) simplicity and b) testing over typing (Bruce Eckel wrote an article > on that, which made a lot of sense to me). At the same time, I'm still > carrying scars from having a few leaks in the abstractions for a data > access API I wrote in my previous job... But these are the things that make us learn. :-) Kind regards robert