C
Christer Nilsson
Is it possible to catch index out of range ?
a = [1,2]
a[99] returns nil, I would like to get an error.
I've tried to define a SafeArray class, but failed.
I managed to redefine Array, but I want to have both possibilities.
class Array
alias old []
def [](index)
raise "index error" if index.abs >= self.size
self.old(index)
end
end
Is there something like Array.indexcheck = true ?
Christer
a = [1,2]
a[99] returns nil, I would like to get an error.
I've tried to define a SafeArray class, but failed.
I managed to redefine Array, but I want to have both possibilities.
class Array
alias old []
def [](index)
raise "index error" if index.abs >= self.size
self.old(index)
end
end
Is there something like Array.indexcheck = true ?
Christer