Convert Hash to OpenStruct recursively

You can monkey-patch the Hash class class Hash def to_o JSON.parse to_json, object_class: OpenStruct end end then you can say h = { a: ‘a’, b: ‘b’, c: { d: ‘d’, e: ‘e’} } o = h.to_o o.c.d # => ‘d’ See Convert a complex nested hash to an object.

Inline comments in Ruby

No, Ruby does not have inline comments. Comments of this style have a tendency to reduce readability, since they makes the code harder to follow. In your case it would be best to split your array items into separate rows and comment out the one row. my_array = [‘first’, # ‘second’, ‘third’, ‘fourth’]

Decode base64 string and write to file

I do not know how you manage to do this, but the line endings \r\n in your string seem to be there as 4-byte character sequences, not as 2-byte escaped CRLF. If I copy your file into a ruby string with single ticks: unescaped=’PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48cmV2aWV3LWNhc2UgY3JlYXRl\r\nZGF0ZT0iMTMvTWFyLzIwMTQgMDk6MDQ6NTEiIHN5c3RlbT0iVHJhZmlndXJhX1RlbXBsYXRlX01h\r\nbmFnZW1lbnRfdjUuMSIgYmF0Y2hpZD0iMCIgdHJhbnNhY3Rpb25ubz0iMSIgYmF0Y2huYW1lPSJH’ Base64.decode64(unescaped) #=> garbled text for every second line if I do …

Read more