You should invoke linearsearch
on an object of type Array
, not pass the array as an argument. As it stands, you are invoking linearsearch
on the ruby top level, which is an instance of Object
, and therefore doesn't have your method defined. Try changing linearsearch
to be invoked on an object of type Array
, like so
class Array
def linearsearch(v)
0.upto(self.length - 1) do |j|
if self[j] == v
return j
end
end
nil
end
end
and invoke it like
dis.linearsearch(9)