From: Chris Dempsey Date: 2009-09-30T20:51:43+09:00 Subject: Re: YAML & String Interpolation --001485f725785fe6ce0474ca27b8 Content-Type: text/plain; charset=ISO-8859-1 Thanks folks. I'll give ERb a shot. On Tue, Sep 29, 2009 at 4:21 PM, trans wrote: > > > On Sep 29, 11:55 am, Chris Dempsey wrote: > > I'm trying to read in a YAML string stored in a configuration file and > have > > Ruby perform String interpolation on it. > > > > For example, > > === YAML file === > > remote_machine: "${server}:${port}" > > > > === RUBY === > > > > def load_settings > > @options = {} > > imports = YAML.load_file('server-info.yaml') > > if imports > > imports.each_pair do |key, value| > > if not key.is_a? Symbol > > imports[key.to_sym] = value > > imports.delete(key) > > end > > end > > @options = imports.merge(@options) > > end > > end > > > > server = '192.168.0.1' > > port = '8080' > > print @options[:remote_machine] # => 192.168.0.1:8080 > > > > Instead what I'm getting is the printing of ${server}:${port}. > > require 'facets/string/interpolate' > server = '192.168.0.1' > String.interpolate{'#{server}'} > > However, I would recommend ERB for this usecase too. > > T. > > > --001485f725785fe6ce0474ca27b8--