From: Ross X Dawson Date: 2007-10-11T14:31:50+09:00 Subject: Using strings to drill down into objects --0__=45BBF9E2DF89366C8f9e8a93df938690918c45BBF9E2DF89366C Content-type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Folks, I'm writing a reporting application where I'm passing in an array of method calls to populate a table e.g. # lambda function to drill down object hierarchy drill_down = lambda do |obj, method_name| o ||= obj method_name.split('.').each {|m| o = o.send(m) if o.respond_to?(m)} o end methods = ['lookup1.code', 'lookup1.name'] report_value = drill_down.call(my_object_with_lookups, methods) I'm sure there is a better "Ruby" way of doing this. Can someone offer some advice? Ross Dawson Developer Data Management & Reporting Link Administration Services Tel Direct: (03) 9633 8165 Tel Office: (03) 9633 8000 ********************************************************************** This communication may contain CONFIDENTIAL information and may also be the subject of LEGAL PROFESSIONAL PRIVILEGE and/or under copyright. If you are not an intended recipient, you MUST NOT keep, forward, copy, use, save or rely on this communication and any such action is unauthorised and prohibited. If you have received this communication in error, please reply to this e-mail to notify the sender of its incorrect delivery, and then delete both it and your reply. Thank you ********************************************************************** --0__=45BBF9E2DF89366C8f9e8a93df938690918c45BBF9E2DF89366C--