def bridge *args, &block
      variables = if args.last.is_a? Hash
                    # We need to sort the key/value pairs to facilitate testing.
                    # This can be removed once 1.8-compat is dropped.
                    key_value_pairs = args.pop.sort {|x,y| x.to_s <=> y.to_s}
                    key_value_pairs.map! {|k,v| "#{k}=#{v}"}
                    "{#{key_value_pairs.join(",")}}"
                  else
                    ""
                  end

      endpoints = if args.first.is_a? Array
                    args.map {|e| e.join(",")}.join("|")
                  else
                    args.join ","
                  end

      application "bridge", variables + endpoints, &block
    end
def bridge *args, &block
      variables = if args.last.is_a? Hash
                    # We need to sort the key/value pairs to facilitate testing.
                    # This can be removed once 1.8-compat is dropped.
                    key_value_pairs = args.pop.sort {|x,y| x.to_s <=> y.to_s}
                    key_value_pairs.map! {|k,v| "#{k}=#{v}"}
                    "{#{key_value_pairs.join(",")}}"
                  else
                    ""
                  end

      endpoints = if args.first.is_a? Array
                    args.map {|e| e.join(",")}.join("|")
                  else
                    args.join ","
                  end

      application "bridge", variables + endpoints, &block
    end
Bridges an incoming call to an endpoint, optionally taking an array of
 channel variables to set. If given an array of arrays, each contained
 array of endpoints will be called simultaneously, with the next array
 of endpoints as failover. See the examples below for different constructs
 and the callstring it sends to FreeSWITCH.
 @example
   bridge "user/coltrane", "user/backup-office"
   #=> user/coltrane,user/backup-office
 @example With channel variables
   bridge "user/coltrane", "user/backup-office", :some_var => "value"
   #=> {some_var=value}user/coltrane,user/backup-office
 @example With failover
   bridge ['user/coltrane', 'user/davis'], ['user/sun-ra', 'user/taylor']
   #=> user/coltrane,user/davis|user/sun-ra,user/taylor
 @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_bridge