I want to check the type of strings that I encounter:
class String
def is_i?
/\A[-+]?\d+\z/ === self
end
def is_path?
pn = Pathname.new(self)
pn.directory?
end
end
def check(key)
puts case key
when is_i?
puts "Could be a number"
when is_path?
puts "This is a path"
else
puts "Ok"
end
end
When I run check("1345425") I get the following error:
undefined method `is_i?' for main:Object (NoMethodError)
What should I do to correct it?
caseworks.