S
S
Sergey Blokhin2018-07-03 18:37:48
ruby
Sergey Blokhin, 2018-07-03 18:37:48

In what situation can a variable be undefined?

There is the following code.
The code is specially prepared for the question.

def method_name(key)
  42.times do
    key
    raise 'raise message'
  end
end

Everything works, but the IDE (RubyMine) gives a warning on the third line that the key variable may not be defined.
Specifically, the warning is:

This inspection reports about dangerous usages of local variables or parameters, such as implicit or undefined local variable or parameter that shadows an outer local variable or parameter. Using data flow analysis, the IDE checks usages of local variables in your code and shows you the possible errors, e.g. that a local variable may not be defined yet on some control flow, etc.

Подскажите, при каких обстоятельствах переменная, явно созданная на этапе вызова метода может быть внутри этого метода быть неопределённой?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question