On Fri, Dec 01, 2006 at 08:45:05AM +0900, dale.quigg / aspentech.com wrote:
} dale.quigg / aspentech.com wrote:
} <snip>
} > However, I want to write a class where I pass something like
} >   '["This"]["Thing"]'
} > or
} >   '["That"]["Thing"]'
} > and then make a call like;
} >   puts LocalTree@YamlLocation
} > but I can't figure out how to make this work.
} 
} Found it, sorry to bother.
} yaml_vari = '["This"]["Thing"]'
} puts eval("LocalTree" + yaml_vari)

In general, eval should be avoided. Try this:

def retrieve(*path)
  path.inject(LocalTree) { |obj,key| obj[key] }
end

Call it as retrieve('This', 'Thing'), for your example.

--Greg