How to suppress "local variable 'foo' can be uninitialized"

已回答

There is a "local variable 'foo' can be uninitialized" if I write like

 

foo if boolean_value

p foo

 

How can I suppress this warning?

I couldn't find configuration for it.

 

2

@Mrtmrt15xn, you can invoke intention action (Alt+Enter) and suppress that inspection for the method.

1

+1 ... Rubymine is complaining the value may be uninitialized when using the safe navigation operator or wrapping the variable access inside an if statement.

0

Hello, sorry for delay! could you please attach the screenshots of the code with inspection? I'm unable to reproduce unfortunately.

0

+1

I can't suppress it, too.

0

@Mrtmrt15xn,

would it be possible to provide a code sample?

0

@Olga-Kuvardina

See the image below.

I know that the variable can be uninitialized. But I just want to hide the warning.

0

Thanks. It works.

0

This is one of the few places I see this warning mentioned. I still get this warning on Ruby 3.2.0 with RubyMine 2023.2.1, and have been seeing it for several versions. It must be a configuration issue, or something specific to my rails project. I can't seem to supress it as mentioned before. Any idea what triggers this warning, and what I can do to get rid of it? 

0

Tyrellj please use Alt+Enter to invoke a popup on the variable with options to suppress the inspection. You can for example suppress it for the method or for a statement.

0

请先登录再写评论。