From: Chris Pelow Date: 2009-11-25T21:13:11+09:00 Subject: Re: Help with each_with_index method Robert Klemme wrote: > 2009/11/25 Chris Pelow : >>> tware Patterns/Person2.rb:40:in `each_with_index' >>> tware Patterns/Person2.rb:40 >> >> Never mind I got it working. >> Thanks a million for your help guys! > > Still a few more remarks: Method #to_s should return something usable > in the general case. In your example, to_s would probably better only > concatenate all three names. Including "Hello" and like stuff feels > wrong because it is unlikely that you always want to print that text > when showing Persons. > > Then, for an absent name nil is a better value than the empty string. > That's exactly what nil stands for, nothing. That also makes > determining whether the person has a middle name easy. > > And a last hint, you can use Struct very effectively to create > complete classes. This can greatly reduce the number of lines you > need for this class. You can find more here: > http://blog.rubybestpractices.com/posts/rklemme/017-Struct.html > > Kind regards > > robert Thanks alot Robert you've been a great help to me. This is the first time i've used this forum and i've found it very helpful so thank you to all that have helped me so far. Chris. -- Posted via http://www.ruby-forum.com/.