Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

hello, new to ruby can someone explain me this function

the << operator is what confuses me the most

  if prev.include? current
    p = reconstruct_path(prev, prev[current])
    [p] << current
  else
    current
  end
end  ```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<< is known as the "shovel". It pushes "things" into other "things". Like this for example:

thing_array = [1,2,3,4,5]
thing_array << 6

Result: => [1, 2, 3, 4, 5, 6]

So the array thing_array was created with the numbers 1-5. By using the shovel I pushed the new entry into the array. It’s just a shortcut to make code cleaner and lighter.

I hope that makes sense.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading