From: Bas van Gils Date: 2007-06-12T15:33:32+09:00 Subject: Re: a matter of style Hi all Robert (and also Anthony), thanks for your comments! On Tue, Jun 12, 2007 at 03:58:21AM +0900, Robert Dober wrote: > (*) Card = Struct.new( :suit, :face ) would be sufficent Right, I wasn't aware of the Struct concept. So there's a first lesson ;) > (*) Ruby allows for much shorter code, look e.g at > def getCard > if @cards.size == 0 > raise "No more cards in the deck" > end > return @cards.slice!(0) > end > which I would write as > def getCard; > @cards.shift or raise SomeNiceErrorClass, "No more cards in the deck" > end That's definitely shorter and more readable... I guess I'll learn to code this way once I get to know the API better. > (*) Personally I think it is nice to name CardSet#shuffle! with the > "!". However more learned members of the community think that the > existance of X#member! implies > X#member and X#member is to be defined as > > def member; x = dup; x.member!; x end > > Just to let you know, I am with you but we are pretty alone ;) Well, it is easy to just add this method if that is to be common Ruby style. Yesterday I read part of Why's poignant guide to Ruby. I noticed that :symbol's are used frequently.. is that also typical Ruby? I˙e. write @someHash = { :foo => "bar" } rather than @someHash = { "foo" => "bar" } is so, is (memory)efficiency the main reason? Cheers Bas -- Bas van Gils , http://www.van-gils.org [[[ Thank you for not distributing my E-mail address ]]] Quod est inferius est sicut quod est superius, et quod est superius est sicut quod est inferius, ad perpetranda miracula rei unius.