lib/bio/data/aa.rb in bio-1.4.3.0001 vs lib/bio/data/aa.rb in bio-1.5.0

- old
+ new

@@ -106,27 +106,25 @@ 'W' => 204.23, 'Y' => 181.19, } def weight(x = nil) - if x - if x.length > 1 - total = 0.0 - x.each_byte do |byte| - aa = byte.chr.upcase - if WEIGHT[aa] - total += WEIGHT[aa] - else - raise "Error: invalid amino acid '#{aa}'" - end + return WEIGHT unless x + + if x.length > 1 + total = 0.0 + x.each_byte do |byte| + aa = byte.chr.upcase + if WEIGHT[aa] + total += WEIGHT[aa] + else + raise "Error: invalid amino acid '#{aa}'" end - total -= NucleicAcid.weight[:water] * (x.length - 1) - else - WEIGHT[x] end + total -= NucleicAcid.weight[:water] * (x.length - 1) else - WEIGHT + WEIGHT[x] end end def [](x) NAMES[x] @@ -235,15 +233,11 @@ private def reverse - hash = Hash.new - NAMES.each do |k, v| - hash[v] = k - end - hash + @reverse ||= NAMES.invert end end @@ -251,21 +245,9 @@ include Data # as class methods extend Data - - private - - - # override when used as an instance method to improve performance - alias orig_reverse reverse - def reverse - unless @reverse - @reverse = orig_reverse - end - @reverse - end end end # module Bio