How can I declare what class a YAML.load() will return so that my IDE will properly identify the loaded object in inspections?

53 views Asked by At

I have a class, JsonConnection. I serialize an instance of that class, connection, to YAML, and store it:

connection = JsonConnection.new
session[:con] = connection.to_yaml

Later, I use the JsonConnection deserialized from the storage throughout my code:

def con
  if session[:con]
    YAML.load(session[:con])
  end
end

Unfortunately, doing things this way means that RubyMine can't seem to tell what class of object con is, and so my code is littered with inspection problems:

Screenshot of inspection issues

Is there a way I can explictly declare that my YAML.load() returns a JsonConnection so that my IDE will be able to identify it properly?

0

There are 0 answers