From: mortee Date: 2007-10-11T21:32:12+09:00 Subject: Re: Using strings to drill down into objects Ross X Dawson wrote: > # 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 not sure what your intent is, but I guess this code won't work. First, unless you define it before creating the lambda, "o" won't exist in its binding, so you can't call o ||= obj. Second, you pass an array of method names to your lambda as a second parameter, on which #split isn't defined. You could state instead: method_name.each{|name| name.split{|part| ... } } but then, "part" would take the value "lookup1", "code", "lookup1" again, and "name" in that order. I highly doubt you want this. However, AFAIK you're right that o.send(m, *args) is the way to call an arbitrary named method on an object. mortee