Calculate Hamming distance between DNA sequences in Ruby
1) Start using Rubocop gem.

2) Prefer guard clauses &amp; stop execution early in a method. (Also, added 2 more conditions.):

raise ArgumentError unless original.length == copy.length
return 0 if original.empty? &amp;&amp; copy.empty?
return 0 if original == copy


3) I would prefer Ruby's #char over #each_char in this case:

original = original.chars
copy     = copy.chars


4) I would prefer Ruby's #zip &amp; #count over #with_index to have a better readability:

strands1.zip(strands2).count { |a, b| a != b }


At the end, it would look something like this:

class Hamming    
  def self.compute(strand1, strand2)
    # Error handling and edge cases
    raise ArgumentError unless strand1.length == strand2.length
    return 0 if strand1.empty? &amp;&amp; strand2.empty?
    return 0 if strand1 == strand2

    strands1, strands2 = strand1.chars, strand2.chars
    # Merge elements of two arrays and compare arrays of array.
    strands1.zip(strands2).count { |a, b| a != b }
  end
end