From: Martin DeMello Date: 2004-09-23T19:34:38+09:00 Subject: Re: String#pad ? Jani Monoses wrote: > Hello > > is there a nicer way of padding a string to a power of two length than for example > > data = data.ljust((data.length+3) & ~3) > > this looks too much like C :) And doesn't even work :) class Fixnum def lg self.to_s(2).length - 1 end end class String def ljust_pow2 self.ljust(2 ** (self.length.lg + 1)) end end p "hello world".ljust_pow2 martin