Ruby Koans' Greed Task
There are a few issues with the code:


Do not check for == nil when it is not specified as a valid value for the method. Here,checking for it and returning 0 might mask another problem.
Do not use return statements unless necessary. In ruby, almost everything is an expression, and methods return the value of the last expression. Here you can use if...elsif, or case instead of a series of if statement.
Do not modify parameters that come into your function (dice.sort!).
Do not use recursion if it makes the code less readable.


Here is a version of the code with the advice above applied:

def score(dice)
  score = 0
  counts = dice.each_with_object(Hash.new(0)) { |x, h| h[x] += 1 }
  (1..6).each do |i|
    if counts[i] &gt;= 3 
      score += (i == 1 ? 1000 : 100 * i)
      counts[i] = [counts[i] - 3, 0].max
    end
    score += counts[i] * (i == 1 ? 100 : 50)
  end
  score
end