Einar Ht wrote:
> Hi,
>
> Still working on the basics... for my card game, I want the Card
> objects to be immutable. Is it sufficient to put 'freeze' in the end
> of the constructor, like this (suit and rank will be strings):
>
> def initialize(suit, rank)
>    @suit, @rank = suit, rank
>    freeze
> end

It's not sufficient, you'll have to freeze those strings, too.  Note that
this will freeze the originals which probably is a bad idea.  You could do

def ini(suit, rank)
  @suit = suit.dup.freeze
  @rank = rank.dup.freeze
  freeze
end

In practice I believe it's rarely seen that people actually use freeze.

HTH

    robert