Skip to content
Junior561 views

What error will you get if you try to write a string with a capital letter?

Practice

AI answer

# Example code that causes this error
# MyString = "This is a string"

NameError: uninitialized constant MyString

Ruby interprets identifiers starting with a capital letter as references to a constant or class. If such a constant or class with this name has not yet been defined in the current scope, Ruby will raise a NameError because it cannot find the corresponding constant.