Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Pasar un hash como argumentos en Ruby

Tengo el siguiente código:

 user = User.from_google(from_google_params) def from_google_params @from_google_params ||= { uid: auth.uid, email: auth.info.email, full_name: auth.info.name, avatar_url: auth.info.image } end

... y aquí está el método from_google al que se pasa el hash.

 def self.from_google(email:, full_name:, uid:, avatar_url:)

Cuando ejecuto esto, aparece un error de argumento ArgumentError (wrong number of arguments (given 1, expected 0; required keywords: email, full_name, uid, avatar_url)):

Esto es lo que veo en la consola:

 >> from_google_params.inspect => "{:uid=>\"100373362533979950619\", :email=>\"marklocklear@extension.org\", :full_name=>\"Mark Locklear\", :avatar_url=>\"https://lh3.googleusercontent.com/a-/AOh14Gh1leKarrW8SCvxxwvaAcDkAISXYQ38k4xPQuC1Rg=s96-c\"}" >> from_google_params.class => Hash

¿Cómo puedo hacer que esto funcione?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Utilice el operador de doble símbolo (**) para convertir el hash en argumentos de palabras clave.

 user = User.from_google(**from_google_params)

La separación de palabras clave y argumentos posicionales fue un gran cambio en Ruby 3. Las versiones anteriores de Ruby convertían el último argumento posicional en palabras clave si era un hash; este comportamiento se depreció en Ruby 2.7 y se eliminó por completo en 3.0.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!