Jack Kelly Jack Kelly - 1 month ago 37
Ruby Question

What does 'no implicit conversion of Regexp into String (TypeError)' mean?

class String
def digit?
self.include?(/[0-9]/)
end
end

Test.assert_equals "".digit?, false
Test.assert_equals "7".digit?, true
Test.assert_equals " ".digit?, false


I have been playing around with regular expressions. Can you tell me how I have made an error? I have tried explicitly converting it to a string but it doesn't work nor do I see why I should have to. Could anyone enlighten me? Thank you!

Answer

include? expects a string as documented here. It seems like you were looking for match.

Comments