From: "David A. Black" Date: 2010-09-10T09:28:11+09:00 Subject: Re: How to do foo.chomp!.rstrip!.downcase! ? Hi -- On Fri, 10 Sep 2010, Geometric Patterns wrote: > > Rather than: > > foo.chomp! > foo.rstrip! > foo.downcase! > > ...it seems like I should be able to do: > > foo.chomp!.rstrip!.downcase! > > ...but I get: undefined method `downcase!' for nil:NilClass > (NoMethodError) > > This is probably a basic ruby thing that I'm not grokking... A lot of destructive ! methods return nil if the object isn't changed -- for example: "abc".gsub!(/z/, "y") => nil So it's generally best not to chain them. David -- David A. Black, Senior Developer, Cyrus Innovation Inc. The Ruby training with Black/Brown/McAnally Compleat Philadelphia, PA, October 1-2, 2010 Rubyist http://www.compleatrubyist.com