1

What I want do is to save Ruby objects for caching to disk. That works nice using YAML or JSON. But when I read that file I want to convert the content back to an object of a special type.

In my case I am using the flickraw library and am using some Ruby code for downloading photos from Flickr. There is a method in flickraw called

photo_info = flickraw.photos.getInfo(:photo_id => photo_id)

which gives me a lot of information about the photo. I dump this information to a file which works great. Since I do not want to download this information every time I run my code but want to read the cached data from the written file I do open the file and then do

file = File.open('photo.meta', 'r')
photo_info = YAML::load(file.read)

Now I need photo_info to become of the object type the getInfo method is returning when using flickraw.

How can I do this in Ruby?

A.A Noman
  • 5,244
  • 9
  • 24
  • 46
hanez
  • 41
  • 5
  • You can serialize the object using Ruby Marshal. A simple way to do that is here - https://stackoverflow.com/a/21520793/2096740 – arjun Feb 19 '18 at 19:49

0 Answers0