Skip to content

Instantly share code, notes, and snippets.

@edivandecastro
Last active February 25, 2025 15:34
Show Gist options
  • Save edivandecastro/1d18c893296ea2a4a013811c9f1ce579 to your computer and use it in GitHub Desktop.
Save edivandecastro/1d18c893296ea2a4a013811c9f1ce579 to your computer and use it in GitHub Desktop.
Youse::SDK::PartnersService::EmployeeIntegrationTools.all(**kwargs).first.tap { unauthorize! if _1.nil? }
@edivandecastro
Copy link
Author

Usando .tap para verificar se o resultado é nil

.tap { unauthorize! if _1.nil? }

  • .tap é um método Ruby que retorna o próprio objeto, permitindo que a gente execute um bloco de código sem alterar o valor retornado.
  • _1 é a forma moderna de acessar o primeiro parâmetro do bloco (introduzido no Ruby 2.7).
  • unauthorize! if _1.nil? → Se o primeiro item da lista for nil, chama unauthorize!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment