class String
remove_method(:each)
end

class Object
def reach
if(x.respond_to?(:each))
self.each{|x| x.reach(yield)}
else
yield(self)
end
end
end

I am getting the error, can't find the local variable 'x'... please help

test examples for code:
[4, 13, 18, "fred", "alice"].each { |x| print x, "\n"}
[4, 13, 18, "fred", "alice"].reach {|x| print x, "\n"}
[4, [13, 88], [19, "fred", "snark"], "alice"].each { |x| print x, "\n"}
[4, [13, 88], [19, "fred", "snark"], "alice"].reach { |x| print x, "\n"}