How to loop through element after an inspect?

In the most general case there is not much you can do. While you can list all methods on an object, you can't tell ahead of time whether these are just accessors or methods that do stuff. Methods might also be added only when needed (eg activerecord objects). You can dump the instance variables from the object, but it may not always be obvious which ones are important and which ones not. If you can make the assumption that all your object share some property (eg all descend from some base class etc...) then your life will be easier

Fred (PS this is a pure ruby thing - no rails magic happening here)

The #<blah key1: value1, key2: value2 ...> comes from YAML. There's no way to pull out all the keys?

Well you can certainly just dump instance variables from the object (which is probably what yaml does most of the time)

I know if the yaml file doesn't contains - !ruby/object:RmEnv, YAML.load will create a hash #<key1: value1, key2: value2 ...> which I can loop through with each_key.

If it's a ruby object, I'm out of luck?

Not so much out of look, most objects just don't have a way for iterating over all their properties (for whatever definition of properties they have)

The data is just a database dump of a Rail Model RmEnv where keys are the db field and the values their values.

You might be better off dumping the attributes of your activerecord objects rather then the whole thing.

Fred

Frederick Cheung wrote: