hash转为查询的conditions

class Hash def to_array_conditions [self.keys.map{|k| "#{k} = ?" }.join(" AND "), self.values].flatten end end test "convert hash conditions to array conditions" do assert_equal ['city = ? AND country_code = ? AND state = ?', "Adendorf", "DE", "Niedersachsen"], { :country_code => "DE", :state => "Niedersachsen", :city => "Adendorf" }.to_array_conditions end

你可能感兴趣的:(hash转为查询的conditions)