Pure ruby implementation of YAML or step by step instructions for setting up native YAML extension in Rhomobile
Is there any pure ruby implementation of YAML? I need to do following (in Rhomobile):
YAML.load( hash_string.to_yaml )
where the hash_string
is a string representation of a hash. I can use neither the standard Ruby YAML library (in Rhomobile framework) nor the eval
function (as it is still not implemented).
I have come across some incomplete implementations of YAML in pure Ruby (e.g., ya2yaml). However, load
and to_yaml
together or the variants of them are probably not supported in the开发者_开发技巧 same library.
Why am I asking this:
Only string data type is supported in Rhom database. A hash attribute of a ruby object gets converted to a string when saved in the database. I would like to get the original hash back (i.e., or convert it from the string) when I retrieve the object from the database. I am open to any other suggestions. I would appreciate if you can provide me with step by step instructions to add the standard Ruby YAML implementation as an extension to Rhomobile framework. I have read the instructions given here. However, I don't know the entry point of the SYCK library that I need to put in ext.yml.
I think regular expression can also be used for this purpose. I am not sure how reliable it would be.
My sincere gratitude to you all.
EDIT: Following worked for me.
Rho::JSON.parse( hash_string.gsub("=>", ":") )
精彩评论