The sheer breadth and depth of the field of Computer Science means that no one programmer is going to have all the answers. The good thing is that programmers tend to collect all their knowledge together on a thing called the Internet. More specifically, there are sites like StackOverflow where programmers ask questions and give answers. Programmers also learn how to read language documentation/APIs (for example the ruby docs) to find their answers.
But mostly importantly, for the time being, programmers learn how to search effectively on Google. Programmers learn that it's not important that you know the answer off the top of your head, it's important that you can find the answer.
Read How to become a programmer, or the art of Googling well
- don't type out full sentences, just use keywords
- add the word 'example' to your query if you want to see an example
- add the specific language you are coding in to your query, e.g. 'ruby'
- use double quotations when you need an exact match in your search
- use type: to narrow answers down by extension
- don't google things that you should be looking in for in the ruby docs (or similar)
- learn to skim a source to see if it looks crazy
- try out the code snippet in a safe place first, like a sandbox or a REPL such as irb