From: Brian Candler Date: 2010-09-08T21:25:26+09:00 Subject: Re: Small improvements ideas ? Christophe Gimenez wrote: > Hello, I would like to know how to shorten these two lines > > 1) doit() if my_string && my_string.downcase == 'hello' doit if /\Ahello\z/i =~ my_string > 2) doit() if one_var && (my_string =~ /this_regexp/) == nil > Case 2) I want doit beeing call if regexp don't match. would I use ! > (my_string =~ /this_regexp/) but I don't like using ! because it's not > very readable and I can't use not keyword in this case I'm not sure what "one_var" is. If you meant "my_string", then note that you can use !~ as the inverse of =~ doit if /this_regexp/ !~ my_string or simply: doit unless /this_regexp/ =~ my_string -- Posted via http://www.ruby-forum.com/.