def expand_varref(varref, lambda_args)
      case varref
      when Symbol, true, false, nil
        varref
      when String
        if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
          prefix, varname, suffix = $1, $2, $3
          prefix = expand_varref(prefix, lambda_args) unless prefix.empty?
          varval = expand_varref(self[varname], lambda_args)
          # suffix needs no expansion since the regex matches the last occurence
          case varval
          when Symbol, true, false, nil, String
            if prefix.is_a?(Array)
              prefix.map {|p| "#{p}#{varval}#{suffix}"}
            else
              "#{prefix}#{varval}#{suffix}"
            end
          when Array
            if prefix.is_a?(Array)
              varval.map {|vv| prefix.map {|p| "#{p}#{vv}#{suffix}"}}.flatten
            else
              varval.map {|vv| "#{prefix}#{vv}#{suffix}"}
            end
          else
            raise "Unknown construction variable type: #{varval.class} (from #{varname.inspect} => #{self[varname].inspect})"
          end
        else
          varref
        end
      when Array
        varref.map do |ent|
          expand_varref(ent, lambda_args)
        end.flatten
      when Proc
        expand_varref(varref[*lambda_args], lambda_args)
      else
        raise "Unknown construction variable type: #{varref.class} (#{varref.inspect})"
      end
    end
def expand_varref(varref, lambda_args)
      case varref
      when Symbol, true, false, nil
        varref
      when String
        if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
          prefix, varname, suffix = $1, $2, $3
          prefix = expand_varref(prefix, lambda_args) unless prefix.empty?
          varval = expand_varref(self[varname], lambda_args)
          # suffix needs no expansion since the regex matches the last occurence
          case varval
          when Symbol, true, false, nil, String
            if prefix.is_a?(Array)
              prefix.map {|p| "#{p}#{varval}#{suffix}"}
            else
              "#{prefix}#{varval}#{suffix}"
            end
          when Array
            if prefix.is_a?(Array)
              varval.map {|vv| prefix.map {|p| "#{p}#{vv}#{suffix}"}}.flatten
            else
              varval.map {|vv| "#{prefix}#{vv}#{suffix}"}
            end
          else
            raise "Unknown construction variable type: #{varval.class} (from #{varname.inspect} => #{self[varname].inspect})"
          end
        else
          varref
        end
      when Array
        varref.map do |ent|
          expand_varref(ent, lambda_args)
        end.flatten
      when Proc
        expand_varref(varref[*lambda_args], lambda_args)
      else
        raise "Unknown construction variable type: #{varref.class} (#{varref.inspect})"
      end
    end
Replace "$!{var}" variable references in varref with the expanded
 variables' values, recursively.

 @param varref [nil, String, Array, Proc, Symbol, TrueClass, FalseClass]
   Value containing references to variables.
 @param lambda_args [Array]
   Arguments to pass to any lambda variable values to be expanded.

 @return [nil, String, Array, Symbol, TrueClass, FalseClass]
   Expanded value with "$!{var}" variable references replaced.