0

I have a string which is an openstruct object. How can I convert it to again to an openstruct?

#<OpenStruct gmail=#<Gmail::Client0xbe112w (abcd@y.com) connected>>

This is a string how can I again convert it to the openstruct object, so that I can access the value

List item
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
AJinkya
  • 21
  • 8
  • 1
    There is no direct way to convert strings to `OpenStruct` - if the string is some kind of structure to it (like JSON or XML or YAML), then, one can write code to parse to a hash and use that to create `OpenStruct` using `OpenStruct::marshal_load` – Wand Maker Jan 25 '16 at 13:28
  • this is a string #> Andrey Deineko – AJinkya Jan 25 '16 at 13:30
  • Check out [this question](http://stackoverflow.com/questions/22765419/ruby-on-rails-string-to-openstruct), it's something alike. – Daniel Batalla Jan 25 '16 at 13:31
  • I checked that before posting the question,it does not work. - Daneil – AJinkya Jan 25 '16 at 13:33
  • `Gmail::Client...` is not an OpenStruct - what you are asking is impossible. – Wand Maker Jan 25 '16 at 13:35
  • I want to pass a gmail object to sidekiq as parameters,so i am putting them in openstruct and passing to sidekiq as params - Wand Maker – AJinkya Jan 25 '16 at 13:39
  • `Gmail::Client` represents a connection to gmail - you cannot pass that around like a Hash or OpenStruct - the `sidekiq` worker should connect to Gmail on its own to get hold of such an object. – Wand Maker Jan 25 '16 at 13:46
  • If i don't pass the object how will the worker get it to know about it, if you have any suggestions can you please tell me – AJinkya Jan 25 '16 at 13:53
  • 2
    I am not an expert on sidekiq, you need to pass simple params and not connection objects. You can post a separate question if your problem is not parsing String to get OpenStruct. This question seems to be [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – Wand Maker Jan 25 '16 at 14:03

0 Answers0