I am doing a coding puzzle where you are a miner in an array, and you can't be out of bounds. I have this code:
if x > minemap.length-1 or x < 0 or y > minemap.length-1 or y < 0
First off, use of
&& in conditions is not idiomatic in Ruby since they have different precedence and may not always do what you want (Style Guide reference).
As for the actual question, something like this is more idiomatic Ruby:
(0...minemap.length).cover?(x) && (0...minemap.length).cover?(y)
This uses Range#cover? to check that
y are inside the correct ranges and returns
false unless that is true.