From: Laran Evans Date: 2009-08-17T11:12:30+09:00 Subject: How can I extract variables from a ruby snippet I have this text: <%= params['post']['category_id'] %> <%= params['post']['title'] %> <%= params['post']['body'] %> <%= params['post']['extended_body'] %> <%= params['post']['private'] %> <% if params['notify'] then %> <% params['notify'].each do |person_id| %> <%= person_id %> <% end %> <% end %> <% if params['attachments'] then %> <% params['attachments'].each do |attachment| %> <%= attachment['name'] %> <%= attachment['file']['temp_id'] %> <%= attachment['file']['content_type'] %> <%= attachment['file'] ['original_filename'] %> <% end %> <% end %> What I need to do is extract all of the variables used in order to learn the variables, and their structure (array/hash vs. simple value) used to render the view. So, using the snippet above, I would learn that there is: - a "post" variable which is a hash, expected to have the keys "category_id", "title", "body", "extended_body" and "private". - a "notify" variable which is an array (indicated by the fact that it's iterated over with the .each) of simple values (i.e. it's not a multi-dimensional array, or an array of hashes) - a "attachments" variable which is an array (again indicated by the fact that it's iterated over with the .each) of hashes (indicated by the fact that each element of the "attachments" array is referenced with hash syntax, i.e. "attachment['name']) and that the value corresponding to the key "file" is also a hash expected to have the keys "temp_id", "content_type" and "original_filename". Is there a tool available to allow me to do this? I haven't been able to find anything. -- Posted via http://www.ruby-forum.com/.