"Ara.T.Howard" <Ara.T.Howard / noaa.gov> schrieb im Newsbeitrag news:Pine.LNX.4.44.0404222216280.8026-100000 / fattire.ngdc.noaa.gov... > > i don't know how many times i've written this... > > spec = '2000GB' > > size = > case spec > when /gb\s*$/io > spec.to_i * (2 ** 30) > when /mb\s*$/io > spec.to_i * (2 ** 20) > when /kb\s*$/io > spec.to_i * (2 ** 10) > else > spec.to_i > end > > is there anything which parses memory specs anywhere in the stdlib? If not, why don't you put it into a file and store that in ~/lib/ruby? Btw. personally I would choose a different implementation. def parse_mem_size(spec) m = /^(\d+) ?(?:([kmgt])b)?$/i.match( spec ) or raise ArgumentError, "Illegal mem spec '#{spec}'" m[1].to_i * case m[2].downcase[0] when ?k; 1024 when ?m; 1048576 when ?g; 1073741824 when ?t; 1099511627776 else 1 end end But I'm sure there are tons of others... :-) robert