Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

488
Visualizações
What does "~~ *" mean in Ruby?

It used in this part of code:

some_list.where("'#{@new_params[:email]}' ~~* name").any?

I tried to use google search, but i found only description of ~ rxp and this same unclear for me (especially in example). I had no experience with Ruby earlier, sorry if question is stupid.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

~~* doen't actually have anything to with Ruby. Its the Postgres specific ILIKE operator for pattern matching.

This code is also a textbook example of a SQL injection vulnerability. The user input should be parameterized.

some_list.where("? ~~* name", @new_params[:email]).any?

This code is also pretty bizarre in that it has a Yoda condition. Normally you would write it as:

some_list.where("name ~~* ?", @new_params[:email]).any?
over 4 years ago · Santiago Trujillo Relatório

0

That has nothing do do with ruby. You construct a sql query and pass it into the #where method therefor it is a PostgreSQL operator.

The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.

That's what you are passing into it:

"foo@bar.com ILIKE name"

over 4 years ago · Santiago Trujillo Relatório

0

Any string in a where clause will be put into the SQL query which is then handed off to the database. So the ~~* syntax is not ruby, but SQL. My guess would be, that you are using Postgres as a DB, because:

The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.

Taken from: https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda