Frederick Cheung wrote: > On Sep 17, 11:05�pm, John Do <[EMAIL PROTECTED]> wrote: >> #<RmEnv label_label_id: 8, data_id: 28, data_val: "MJP-QA2"> >> [code] >> record.each do |key| >> � puts record[key] >> end[/code] >> >> But RoR throw an error, undefined method 'each' for #<RmEnv ... > > > 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? 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? The data is just a database dump of a Rail Model RmEnv where keys are the db field and the values their values. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

