1

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?

David Gay
  • 1,094
  • 2
  • 16
  • 32
  • I don't use RubyMine, so I haven't tried this, but did you take a look at this answer? https://stackoverflow.com/a/25455873/2981429 – max pleaner Jun 15 '20 at 16:50
  • what does the `JsonConnection` class look like? you can declare ruby objects in yml files and load them as the given object via `YAML.dump` and `YAML.load` given that the constructors are correct to support this [Here](https://skorks.com/2010/04/serializing-and-deserializing-objects-with-ruby/) is a fairly old but still germane example – engineersmnky Jun 15 '20 at 17:20

0 Answers0