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

junior

Can you call a private method outside a Ruby class using its object?

senior

When might you encounter a LocalJumpError ?

middle

Which operator must be defined in order to implement the Comparable module?

Bình luận

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

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