Câu hỏi phỏng vấn Ruby
Câu hỏi

What happens to a consta...

Câu trả lời

In Ruby, constants must be assigned a value when they are declared. If a constant is referenced without being assigned a value, Ruby will raise a "NameError" indicating an "uninitialized constant" [2][3]. This error occurs because Ruby constants are expected to be defined with a value before they are used. Unlike some other programming languages where constants or variables might be automatically initialized to a default value (like null or 0), Ruby requires explicit initialization of constants.

For example, attempting to use a constant without initializing it, like this:

ruby Copy
puts MyConstant

will result in:

Copy
NameError: uninitialized constant MyConstant

This error message is Ruby's way of e...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What are two uses of ranges?

junior

What does it mean to coerce an object? Why would you do it?

entry

What are rubygems?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào