From: Robert Klemme Date: 2009-11-25T21:02:06+09:00 Subject: Re: Help with each_with_index method 2009/11/25 Chris Pelow : > Chris Pelow wrote: >> Still getting this error at runtime however >> >> >> >> s/Person2.rb:22:in `full_name': undefined method `empty?' for >> nil:NilClass (NoMethodError) >> tware Patterns/Person2.rb:41 >> tware Patterns/Person2.rb:43:in `each_with_index' >> tware Patterns/Person2.rb:40:in `each' >> 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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/