CodeWars Solution to "Simple Elevator"
Your solution looks correct, though it is a bit long.

One way to shorten it is to remove the elses:

def goto(level, button)
  inputs_types_are_accepted = (level.is_a? Integer) &amp;&amp; (button.is_a? String)
  if inputs_types_are_accepted
    current_floor, desired_floor = level.to_i, button.to_i
    if current_floor.between?(0, 3) &amp;&amp; desired_floor.between?(0, 3)
      floor_change = desired_floor - current_floor
      return floor_change
    end
  end
  # Don't move elevator if the input is wrong in any way
  0
end


You don't need to do level.to_i when you have already ascertained that level is an Integer. You can also eliminate the variables inputs_types_are_accepted and floor_change.

(current_floor &amp;&amp; desired_floor) won't work.  In English, you can ask whether "the current floor and desired floor are both between 0 and 3", but you can't translate that literally into Ruby.  Since you want to perform two tests, you have to write it as two tests.  The way the &amp;&amp; operator works is that it will return the left operand (current_floor) if it is considered true — and in Ruby, every integer is considered to be true.

One thing that I like about your solution and that I dislike about the "top-voted" solution is that the latter does not extend well to handle more than 10 floors.  Although the problem states that there are just 4 levels, but still, using ('0'..'3').include?(button) to validate the floor in the string domain rather than the integer domain feels like a hack to me.

Obviously, there are many possible formulations.  It's a new moon today, so I feel like writing it this way:

def goto(level, button)
  floors = (0..3)

  # Validation: don't move elevator on invalid input
  return 0 unless button.kind_of?(String) &amp;&amp; floors === (dest = button.to_i)
  return 0 unless floors === level

  dest - level
end


The way you wrote your solution tends to lead to deeper nesting.  As a rule of thumb, it is preferable to return early on failure, since there are usually many ways to fail, but only one way to succeed.