From: Brian Adkins Date: 2007-10-12T01:05:02+09:00 Subject: Re: Using strings to drill down into objects On Oct 11, 8:32 am, mortee wrote: > 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. Are you sure about that? brian@imagine:~$ irb irb(main):001:0> x ||= 7 => 7 irb(main):002:0> x => 7