I have an array
You could do this, but you shouldn't need to. You're going about this the wrong way, I feel, since the responsibility is yours, not Array's, to check the index value being passed.
Merely an example
def get_array_value (i) return data_array[i - 1] unless i < 0 return nil end
However, if you insist, this solution may work for you.
# arr = SpecialArray.new([1, 2, 3, 4, 5]) class SpecialArray < Array def (i) return super(i) unless i < 0 return nil end end