From: Brian Candler Date: 2007-05-08T22:47:31+09:00 Subject: Re: general purpose chomp? On Tue, May 08, 2007 at 09:33:43PM +0900, Robert Dober wrote: > On 5/8/07, Michal Suchanek wrote: > >I wonder why we do not have one. Or maybe I just overlooked something? > > > >class String > > def lstripc c = ' \r\t\n' > > c = c.chr if c.kind_of? Integer > > idx = 0 > > while c.include? self[idx] > > idx += 1 > > end > > self[idx..-1] > > end > >end > > > >Thanks > > > >Michal > > > > > Some random thoughts > * Chomp strips on the RHS of the string, right? > * Sometimes I would just use sub /^/, "" Except that would be wrong in this case, since it wouldn't only chomp from the left-hand side of the string. Use /\A.../ not /^.../